18

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
Chris Pfohl
  • 18,220
  • 9
  • 68
  • 111
Kerby82
  • 4,934
  • 14
  • 48
  • 74

2 Answers2

59

Use the title method of str:

'ac milan'.title()
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
8

Is this what you're looking for?

>>> "how now brown cow".title()
'How Now Brown Cow'
Ryan Ginstrom
  • 13,915
  • 5
  • 45
  • 60