- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Python String Methods part 2 #pythonforbeginners #python3 #phython #learnpython #pythontutorial
The `strip()` method in Python is a string method used to remove leading and trailing whitespaces (spaces, tabs, and newlines) from a string. The method returns a new string with the leading and trailing whitespaces removed.
Here's an example:
```python
text = " Python Programming "
stripped_text = text.strip()
print("Original:", repr(text)) # repr() is used to display whitespaces
print("Stripped:", repr(stripped_text))
```
Output:
```
Original: ' Python Programming '
Stripped: 'Python Programming'
```
In this example, the `strip()` method removes the leading and trailing whitespaces from the original string, resulting in a new string without those spaces.
It's important to note that `strip()` only removes leading and trailing whitespaces, not spaces within the string.
You can also use `lstrip()` and `rstrip()` if you want to remove whitespaces only from the left or right side of the string, respectively.
Here's an example:
```python
text = " Python Programming "
left_stripped_text = text.lstrip()
right_stripped_text = text.rstrip()
print("Original:", repr(text))
print("Left Stripped:", repr(left_stripped_text))
print("Right Stripped:", repr(right_stripped_text))
```
Output:
```
Original: ' Python Programming '
Left Stripped: 'Python Programming '
Right Stripped: ' Python Programming'
```
In this example, `lstrip()` removes leading whitespaces, and `rstrip()` removes trailing whitespaces.
Видео Python String Methods part 2 #pythonforbeginners #python3 #phython #learnpython #pythontutorial канала pythonbuzz
Here's an example:
```python
text = " Python Programming "
stripped_text = text.strip()
print("Original:", repr(text)) # repr() is used to display whitespaces
print("Stripped:", repr(stripped_text))
```
Output:
```
Original: ' Python Programming '
Stripped: 'Python Programming'
```
In this example, the `strip()` method removes the leading and trailing whitespaces from the original string, resulting in a new string without those spaces.
It's important to note that `strip()` only removes leading and trailing whitespaces, not spaces within the string.
You can also use `lstrip()` and `rstrip()` if you want to remove whitespaces only from the left or right side of the string, respectively.
Here's an example:
```python
text = " Python Programming "
left_stripped_text = text.lstrip()
right_stripped_text = text.rstrip()
print("Original:", repr(text))
print("Left Stripped:", repr(left_stripped_text))
print("Right Stripped:", repr(right_stripped_text))
```
Output:
```
Original: ' Python Programming '
Left Stripped: 'Python Programming '
Right Stripped: ' Python Programming'
```
In this example, `lstrip()` removes leading whitespaces, and `rstrip()` removes trailing whitespaces.
Видео Python String Methods part 2 #pythonforbeginners #python3 #phython #learnpython #pythontutorial канала pythonbuzz
python strip method in python python strip function python string methods python strip strip in python learn python python programming python tutorial python string python strip method python string strip python for beginners strip method python python strip string string methods in python python strings strip strip function in python string methods strings in python python tutorials string strip python strip method python strip string method naruto
Комментарии отсутствуют
Информация о видео
20 февраля 2024 г. 17:16:20
00:01:00
Другие видео канала




















