Welcome Quillix Python Tutorial. In previous chapter, we have covered some Python string methods. Now we will learn about other string methods that help us to modify and write program.
String Methods or Functions
Replace()
Using this method, user can replace character or word with another.
Syntax: string.replace(old, new)
name = "Quillix Blogspot"
new_name = name.replace("Blogspot", "Python Tutorial")
print(new_name) #Output: Quillix Python Tutorial
Split()
It allows coder to split string in list. By default, it use space to split string but we can also mention specific character to split data.
my_text = "How are you?"
result = my_text.split()
print(result)Find()
This method returns the index of the string's position. If it does not find the word, it outputs -1.
str = "Today is my birthday"
print(str.find("birthday"))
Count()
Use this method to count the word in string.text = "Python Python Quillix"print(text.count("Python"))
Startswith()
If you want to check the string starting word then we can use startswith() method.
text = "Python Programming"
print(text.startswith("Python"))Endswith()
This method helps you to find end word true or false.
text = "Python Programming"
print(text.endswith("Python"))Strip()
We are already learn this method It removes space start and end.
myText = " Python Programming " print(myText.strip())
Upper() and Lower()
myText1 = "python programming" print(myText1.upper())
myText2 = "PYTHON" print(myText2.lower())
Join()
Joins elements of a list into a string.
joinWord = ("Quillix", "Python", "Tutorial")
print(" ".join(joinWord))Capitalize()
Make first letter capital (upper case).myText4 = ("Python is easy to learn")
print(myText4.capitalize())
Final Thoughts
We have completed the String chapter in Python. The next chapter will cover the input() function. Read this tutorial and practice as much as you can. Also share with others who wants to learn python in simple word.
