Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

case in python

def http_error(status):
    match status:
        case 400:
            return "Bad request"
        case 404:
            return "Not found"
        case 418:
            return "I'm a teapot"
        case _:
            return "Something's wrong with the internet"
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

case python

lang = input("What's the programming language you want to learn? ")

match lang:
    case "JavaScript":
        print("You can become a web developer.")

    case "Python":
        print("You can become a Data Scientist")

    case "PHP":
        print("You can become a backend developer")
    
    case "Solidity":
        print("You can become a Blockchain developer")

    case "Java":
        print("You can become a mobile app developer")
    case _:
        print("The language doesn't matter, what matters is solving problems.")
Comment

PREVIOUS NEXT
Code Example
Python :: mistborn series 
Python :: read csv in spark 
Python :: python string formatting - padding 
Python :: how to check whether input is string or not 
Python :: python replace in string 
Python :: python mongodb connection 
Python :: node 14 alpine add python 
Python :: np.zero 
Python :: normal discord.py codes 
Python :: how to find min, max in dictionaries 
Python :: functools python install 
Python :: pyspark groupby with condition 
Python :: request.args.get check if defined 
Python :: how to import something in python 
Python :: quick sort algorithm in python 
Python :: PySimple list of elements 
Python :: how to open youtube from google chrome browser instead of internet explorerwhen coding in python 
Python :: Reversing Ints 
Python :: python divide and round away operator 
Python :: python save images from directory to list 
Python :: Access field values of form django 
Python :: how to insert values to database with using dictionary in python 
Python :: .unique() python 
Python :: split() vs split() 
Python :: string remove suffix python 
Python :: python async await function 
Python :: python code for create diamond shape with integer 
Python :: plotly pdf report 
Python :: maximum recursion depth exceeded while calling a Python object 
Python :: repl.it secret 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =