Files
30-seconds-of-code/snippets/decapitalize.md
2019-10-06 19:48:51 +00:00

547 B

title, tags
title tags
decapitalize string,intermediate

Decapitalizes the first letter of a string.

Decapitalize the first letter of the string and then add it with rest of the string. Omit the upper_rest parameter to keep the rest of the string intact, or set it to True to convert to uppercase.

def decapitalize(input_string, upper_rest=False):
  return input_string[:1].lower() + (input_string[1:].upper() if upper_rest else input_string[1:])
decapitalize('FooBar') # 'fooBar'
decapitalize('FooBar', True) # 'fOOBAR'