You can download this code by clicking the button below.
This code is now available for download.
This function takes an input string and a format type to transform the string to a specific case format.
Technology Stack : str.lower(), str.upper(), str.title(), str.swapcase(), str.capitalize()
Code Type : String formatting
Code Difficulty :
def format_string(input_string, format_type='lower'):
if format_type == 'lower':
return input_string.lower()
elif format_type == 'upper':
return input_string.upper()
elif format_type == 'title':
return input_string.title()
elif format_type == 'swapcase':
return input_string.swapcase()
elif format_type == 'capitalize':
return input_string.capitalize()
else:
return input_string