capitalize first letter python code example

Example 1: how to capitalize first letter in python

# 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

Example 2: capitalize first letter of each word python

"hello world".title()
'Hello World'
>>> u"hello world".title()
u'Hello World'

Example 3: change to first letter capital list python

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

Example 4: python lowercase first letter

def decapitalize(str):
    return str[:1].lower() + str[1:]

print( decapitalize('Hello') )          # hello