Part 8: String Methods in Python (Beginner Friendly Explanation)
Автор: Akash Solkar
Загружено: 2025-11-26
Просмотров: 0
Описание:
Python gives us many built-in methods to work with strings (change case, find text, replace text, etc.).
✅ 1. upper()
Converts all characters to UPPERCASE.
name = "JP Morgen"
print(name.upper()) # JP Morgen
✅ 2. lower()
Converts all characters to lowercase.
city = "MUMBAI"
print(city.lower()) # mumbai
✅ 3. title()
Converts the first letter of every word to capital.
text = "welcome to python"
print(text.title()) # Welcome To Python
✅ 4. strip()
Removes extra spaces from start and end.
msg = " hello "
print(msg.strip()) # "hello"
✅ 5. replace(old, new)
Replaces a part of the string with something else.
data = "I love Java"
print(data.replace("Java", "Python"))
I love Python
✅ 6. split()
Breaks a string into a list (using spaces or given separator).
line = "apple,banana,orange"
print(line.split(","))
['apple', 'banana', 'orange']
✅ 7. find()
Returns the index number where a substring is found.
text = "hello world"
print(text.find("world")) # 6
✅ 8. len() (not a method, but useful)
Returns length of the string.
msg = "python"
print(len(msg)) # 6
🎯 Summary
String methods help you:
Change text case
Remove spaces
Find or replace text
Break strings into parts
Measure length
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: