Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python switch statement

def f(x):
    match x:
        case 'a':
            return 1
        case 'b':
            return 2
        case _:
            return 0   # 0 is the default case if x is not found
Comment

python switch

# Python 3.10.0 +
match subject:
    case <pattern_1>:
        <action_1>
    case <pattern_2>:
        <action_2>
    case <pattern_3>:
        <action_3>
    case _:
        <action_wildcard>
Comment

python switch case

match points:
    case []:
        print("No points in the list.")
    case [Point(0, 0)]:
        print("The origin is the only point in the list.")
    case [Point(x, y)]:
        print(f"A single point {x}, {y} is in the list.")
    case [Point(0, y1), Point(0, y2)]:
        print(f"Two points on the Y axis at {y1}, {y2} are in the list.")
    case _:
        print("Something else is found in the list.")
Comment

python switch

>>> def week(i):
        switcher={
                0:'Sunday',
                1:'Monday',
                2:'Tuesday',
                3:'Wednesday',
                4:'Thursday',
                5:'Friday',
                6:'Saturday'
             }
         return switcher.get(i,"Invalid day of week")<div class="open_grepper_editor" title="Edit & Save To Grepper"></div>
Comment

python switch item

def operations(letter):
    switch={
       'a': "It is a vowel",
       'e': "It is a vowel",
       'i': "It is a vowel",
       'o': "It is a vowel",
       'u': "It is a vowel",
       }
    return switch.get(letter,"It is a not a vowel")		# disregard 2nd parameter
operations('a')
Comment

PREVIOUS NEXT
Code Example
Python :: how to pass csrf token in post request django 
Python :: how to comment python 
Python :: pandas if nan, then the row above 
Python :: gene wilder pure imagination 
Python :: avoid bad request django 
Python :: cv2.imwrite path 
Python :: stackoverflow python 
Python :: python unpack list 
Python :: python json nan 
Python :: newtorkx remove node 
Python :: rest plus 
Python :: sklearn tree visualization 
Python :: merge sort python 
Python :: Python NumPy stack Function Example with 1d array 
Python :: import modules given the full path python 
Python :: binary search tree implementation in python 
Python :: fonction nombre premier python 
Python :: python sh command 
Python :: getting python class from string 
Python :: .dropna() python 
Python :: dash authentication 
Python :: creating python classes 
Python :: open python not write file 
Python :: python colored text in console 
Python :: python startswith method 
Python :: selenium webdriver without opening browser 
Python :: multiple logger instances populating single log python 
Python :: python basics 
Python :: quotation marks in string 
Python :: mean pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =