String Formatting Function Overview

  • Share this:

Code introduction


This function converts the input text to different string formats based on the specified format type, such as uppercase, lowercase, title case, etc.


Technology Stack : String (str)

Code Type : String formatting function

Code Difficulty : Intermediate


                
                    
def string_formatting(text, format_type):
    if format_type == 'upper':
        return text.upper()
    elif format_type == 'lower':
        return text.lower()
    elif format_type == 'title':
        return text.title()
    elif format_type == 'capitalize':
        return text.capitalize()
    else:
        return "Unknown format type"                
              
Tags: