String Formatting Function

  • Share this:

Code introduction


This function converts the input string to uppercase, lowercase, or title case based on the specified format type.


Technology Stack : str.upper(), str.lower(), str.title()

Code Type : String formatting function

Code Difficulty : Intermediate


                
                    
def format_string(input_string, format_type='upper'):
    if format_type == 'upper':
        return input_string.upper()
    elif format_type == 'lower':
        return input_string.lower()
    elif format_type == 'title':
        return input_string.title()
    else:
        return input_string