Python has many build-in methods, these methods belong to a data-type now i will to explain the most common string methods
capitalize = this method returns some string but with the first character in uppercase.
my_string = 'random word'
capitalize_word = my_string.capitalize()
print(capitalize_word)
output : 'Random word'
lower = this method returns a copy of the string with all characters in lowercase.
my_string = 'Random WORD'
lower_word = my_string.lower()
print(lower_word)
output : 'random word'
upper = this method returns a copy of the string with all characters in uppercase.
my_string = 'Random WORD'
upper_word = my_string.upper()
print(upper_word)
output : 'RANDOM WORD'
swapcase() = this method change the characters , if the character is uppercase change for lowercase, does the same for the opposite case.
my_string = 'RANDOM word'
swap_word = my_string.swapcase()
print(swap_word)
output : 'random WORD'
Top comments (0)