xxxxxxxxxx
string = "hello world"
capitalized = string[0].upper() + string[1:]
print(capitalized)
xxxxxxxxxx
my_string = "programiz is Lit"
cap_string = my_string.capitalize()
print(cap_string)
xxxxxxxxxx
singers = ['johnny rotten', 'eddie vedder', 'kurt kobain', 'chris cornell', 'micheal phillip jagger']
singers = [singer.capitalize() for singer in singers]
print(singers)
#instead of capitalize use title() to have each word start with capital letter
xxxxxxxxxx
>>> "hello world".title()
'Hello World'
>>> u"hello world".title()
u'Hello World'
xxxxxxxxxx
# To capitalize the first letter in a word or each word in a sentence use .title()
name = tejas naik
print(name.title()) # output = Tejas Naik
xxxxxxxxxx
my_string = "programiz is Lit"
print(my_string[0].upper() + my_string[1:])
xxxxxxxxxx
import camelcase
c = camelcase.CamelCase()
txt = "Welcome Dear ismail "
print(c.hump(txt))
xxxxxxxxxx
"hello world".title()
'Hello World'
>>> u"hello world".title()
u'Hello World'
xxxxxxxxxx
def decapitalize(str):
return str[:1].lower() + str[1:]
print( decapitalize('Hello') ) # hello
xxxxxxxxxx
# Use title() to capitalize the first letter of each word in a string.
name = "elon musk"
print(name.title())
# Elon Musk