Featured
- Get link
- X
- Other Apps
String methods
Strings are the most popular types in python. A string is a sequence of characters they can be letter, a number or a backslash. Python strings are immutable which means they cannot be changed after they are created.
String is a continuous set of character represented inside single' ' or double" " quote.
Lets see some string built in methods:
1) length- It returns the length of the string
2) count- count how many times the particular character is available in string
3) find- find the location of ths particular character in the string
4) concatenate string- to add another string in python to concatenate we use "+" Operator
5) lower- convert all uppercase letters to lowercase
6) upper- convert all lowercase letters to uppercase
7) islower- return true if string has lowercase characters and false otherwise
8) isupper- return true if string has upper characters and false otherwise
9) isnumeric- return true if string contains numeric only numeric character and false otherwise
10) capitalize- return the string with its first character capitalized and the rest lowercased
11) title- return title version of the string
12) max- return max alphabetical character from the string
13) min- return min alphabetical character from the string
These are the basic string methods which we use. Now lets see the example using these methods
Example:
print(str)
print("length of str:")
print(len(str))
print("lets count a:")
print(str.count('a'))
print("position of h:")
print(str.find("h))
print("convert uppercase to lowercase:")
print(str.lower())
print("convert lowercase to uppercase:")
print(str.upper())
print("does it contain lowercase:")
print(str.islower())
print("does it contain uppercase:")
print(str.isupper())
print("does it contain number:")
print(str.isnumeric())
print("capitalize:")
print(str.capitalize())
print("title version:")
print(str.title())
Output:
if you have any doubts in string methods feel free to comment!!!!
- Get link
- X
- Other Apps

Comments
Post a Comment