Below, you can see a table of various built-in functions and string methods. Click on any one to learn more about it.
6. find()
1
2
3 | #find(substring, lower limit, upper limit)
string = "Welcome to the Q-Programming website!"
print(string.find("we", 0,35))
|
Here we get the output as 29
because the first instance of "we"
is at the the 29th index in the string.
1
2
3 | #find(substring, lower limit, upper limit)
string = "Welcome to the Q-Programming website!"
print(string.find("x", 0,35))
|
Here we got the output as -1
because "x"
is not present in the string.
7. index()
1
2
3 | #index(substring, lower limit, upper limit)
string = "Welcome to the Q-Programming website!"
print(string.index("we", 0,35))
|
Here we got the same output as the first case for find()
.
1
2
3 | #index(substring, lower limit, upper limit)
string = "Welcome to the Q-Programming website!"
print(string.index("x", 0,35))
|
Output
Traceback (most recent call last):
File "<string>", line 3, in <module>
ValueError: substring not found
As you can see, we get a ValueError
when a substring is not found by the index()
method.
8. endswith()
1
2 |
string = "Welcome to the Q-Programming website!"
print(string.endswith("!"))
|
1
2 |
string = "Welcome to the Q-Programming website!"
print(string.endswith("a"))
|
9. startswith()
1
2 |
string = "Welcome to the Q-Programming website!"
print(string.startswith("W"))
|
1
2 |
string = "Welcome to the Q-Programming website!"
print(string.startswith("e"))
|
10. isalnum()
1
2 |
string = "Welcome to the Q-Programming website"
print(string.isalnum())
|
1
2 |
string = "Welcome to the Q-Programming website!"
print(string.isalnum())
|
In the second case, the output was False
because of the presence of "!"
, which is a special character.
11. islower()
1
2 |
string = "qprogramming"
print(string.islower())
|
1
2 |
string = "Qprogramming"
print(string.islower())
|
12. isupper()
1
2 |
string = "QPROGRAMMING"
print(string.isupper())
|
1
2 |
string = "Qprogramming"
print(string.isupper())
|
13. isspace()
1
2 |
string = " "
print(string.isspace())
|
1
2 |
string = "Q-Programming"
print(string.isspace())
|
14. istitle()
1
2 |
string = "Welcome To QProgramming"
print(string.istitle())
|
1
2 |
string = "welcome to qprogramming"
print(string.istitle())
|
15. lstrip()
1
2 | string = " Q-Programming"
print(string.lstrip())
|
16. rstrip()
1
2 | string = "Q-Programming "
print(string.rstrip())
|
17. strip()
1
2 | string = " Q-Programming "
print(string.strip())
|
18. replace()
1
2
3 | #replace(original substring,new substring)
string = "Welcome to Q Programming"
print(string.replace(" ","-"))
|
Output
Welcome-to-Q-Programming
19. join()
1
2
3 | #replace(original substring,new substring)
string = "Welcome to Q Programming"
print(string.replace(" ","-"))
|
Output
Q*P*r*o*g*r*a*m*m*i*n*g
20. partition()
1
2
3 | #ssting.paritiion(separator)
string = "Welcome to Q-Programming!"
print(string.partition("to"))
|
Output
('Welcome ', 'to', ' Q-Programming!')
21. split()
1
2
3 | #ssting.paritiion(delimiter)
string = "Welcome to Q-Programming!"
print(string.partition("to"))
|
Output
['Welcome ', ' Q-Programming!']
That's it for this tutorial! Scroll up and click on Next for the next tutorial!
For information on how you can use this information, please refer to our Terms
of Use