Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python First Letter of a word Upper CASE [duplicate]

Tags:

python

I'm looking for some very clever and fast way of transforming every first character of a word in a string with the upper case.

ac milan > Ac Milan
paris saint germain > Paris Saint Germain
like image 664
Kerby82 Avatar asked Mar 14 '11 13:03

Kerby82


People also ask

How do you print the first letter of the upper case in Python?

string capitalize() in Python Python String capitalize() method returns a copy of the original string and converts the first character of the string to a capital (uppercase) letter, while making all other characters in the string lowercase letters.

How do you capitalize the first letter of each word in Python?

capwords() capwords() is a python function that converts the first letter of every word into uppercase and every other letter into lowercase. The function takes the string as the parameter value and then returns the string with the first letter capital as the desired output.

How do you uppercase every first letter of a word in a string?

To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it.

How do you check if the first letter of a string is capitalized Python?

To check if a string is in uppercase, we can use the isupper() method. isupper() checks whether every case-based character in a string is in uppercase, and returns a True or False value depending on the outcome.


1 Answers

Use the title method of str:

'ac milan'.title()
like image 84
Fred Foo Avatar answered Sep 28 '22 19:09

Fred Foo