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
  • 16,750
  • 9
  • 66
  • 107
Kerby82
  • 4,725
  • 14
  • 45
  • 70

2 Answers2

59

Use the title method of str:

'ac milan'.title()
Fred Foo
  • 342,876
  • 71
  • 713
  • 819
8

Is this what you're looking for?

>>> "how now brown cow".title()
'How Now Brown Cow'
Ryan Ginstrom
  • 13,577
  • 5
  • 42
  • 59