Skip to content

Home

Capitalize string

Capitalizes the first letter of a string.

def capitalize(s, lower_rest = False):
  return ''.join([s[:1].upper(), (s[1:].lower() if lower_rest else s[1:])])

capitalize('fooBar') # 'FooBar'
capitalize('fooBar', True) # 'Foobar'

More like this

Start typing a keyphrase to see matching snippets.