Ram
Ram

Reputation:

Make the first character uppercase in python 3.4.1

I know that you can make a whole statement capital by using ".upper" but .upper() but how do you just make just the first word capital on input statement?

How would I make it in this case?

custumer_name = input(format("Enter Custumer's name: ",">27s"))
print (custumer_name)

What I would like to do is that, if I input "peter", it capitalizes the first letter "P" and then it prints it as "Peter".

Upvotes: 1

Views: 2001

Answers (2)

xnx
xnx

Reputation: 25478

If you want just the first word capitalized, use capitalize. If you want all words capitalized (e.g. for a name written as Firstname Surname), use title:

>>> s = 'peter jones'
>>> s.capitalize()
'Peter jones'
>>> s.title()
'Peter Jones'

Upvotes: 3

PeterE
PeterE

Reputation: 5855

Short answer:

str.capitalize()

Use like this:

s = "peter".capitalize()

or

s = "peter"
s = s.capitalize()

Lots of other useful information in the docs

Upvotes: 6

Related Questions