You can download this code by clicking the button below.
This code is now available for download.
This function formats the input string based on the provided format type, such as title case, upper case, lower case, and so on.
Technology Stack : String manipulation
Code Type : String formatting function
Code Difficulty : Intermediate
def format_string(input_string, format_type):
if format_type == "title":
return input_string.title()
elif format_type == "upper":
return input_string.upper()
elif format_type == "lower":
return input_string.lower()
elif format_type == "capitalize":
return input_string.capitalize()
elif format_type == "swapcase":
return input_string.swapcase()
else:
return input_string