python capitalize() on a string starting with space
This is the listed behaviour:
Return a copy of the string with its first character capitalized and the rest lowercased.
The first character is a space, the space is unchanged, the rest lowercased.
If you want to make it all uppercase, see str.upper()
, or str.title()
for the first letter of every word.
>>> phrase = 'lexical semantics'>>> phrase.capitalize()'Lexical semantics'>>> phrase.upper()'LEXICAL SEMANTICS'>>> phrase.title()'Lexical Semantics'
Or, if it's just a problem with the space:
>>> phrase = ' lexical semantics'>>> phrase.strip().capitalize()'Lexical semantics'
.capitalize()
capitalises the first character ... which is a space :) Every other character gets lowercased.