Python String | capitalize method
str.capitalize(~) method converts the first character of the string to titlecase, and all other characters to lowercase. This means that digraph characters will only have their first letter capitalized.
A new string with the first character of the string converted to titlecase.
To convert first letter of
"hello there. How aRe you?" to titlecase and all other characters to lowercase:
x = "hello there. How aRe you?"x.capitalize()'Hello there. how are you?'
Note that the source string
x is kept intact and a new string is returned. This can be confirmed if we print
hello there. How aRe you?
The original string is unchanged, even after being used with