Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python switch case 3.10 Structural Pattern Matching

#From python 3.10 on, pattern matchin (switch case) has been added

def http_error(status):
    match status:
        case 400:
            return "Bad request"
        case 404:
            return "Not found"
        case 418:
            return "I'm a teapot"
        case 401|403|404:
          	return "Not allowed"
        case _:
            return "Something's wrong with the internet"

#Source: https://docs.python.org/3/whatsnew/3.10.html
Comment

PREVIOUS NEXT
Code Example
Python :: for enumerate python 
Python :: python datetime greater than now 
Python :: float to int in python 
Python :: print input in python 
Python :: convert a text file data to dataframe in python without pandas 
Python :: subprocess.popen no output 
Python :: how to get python list length 
Python :: precision and recall from confusion matrix python 
Python :: python unittest discover 
Python :: inser elemts into a set in python 
Python :: dict to attr python 
Python :: concatenate string and int python 
Python :: Get the square root of a number in Python 
Python :: pandas df represent a long column name with short name 
Python :: python generate set of random numbers 
Python :: .split python 
Python :: Flask command db migrate 
Python :: python dictionary sort by value then alphabetically 
Python :: compare times python 
Python :: pandas replace nan with value above 
Python :: split pdf python 
Python :: how to change todays date formate in python 
Python :: string acharacters count in python without using len 
Python :: fibinacci python 
Python :: python how to get last element in a list 
Python :: py to exe 
Python :: labelencoder update 
Python :: test with python 
Python :: line plotly with shaded area 
Python :: Python not readable file 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =