Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 case statement Using classes

class PythonSwitch:
    def day(self, dayOfWeek):

        default = "Incorrect day"

        return getattr(self, 'case_' + str(dayOfWeek), lambda: default)()

    def case_1(self):
        return "monday"

def case_2(self):
        return "tuesday"

 def case_3(self):
        return "wednesday"

   
def case_4(self):
       return "thursday"

  def case_5(self):
        return "friday"

   def case_7(self):
        return "saturday"
    
    def case_6(self):
        return "sunday"

my_switch = PythonSwitch()

print (my_switch.day(1))

print (my_switch.day(3))
Comment

PREVIOUS NEXT
Code Example
Python :: tkinter bind function with arguments 
Python :: get more than one decimal in python 
Python :: python is instance numpy arrya 
Python :: how to print multiple integers in python in different line 
Python :: rezise object pygame 
Python :: how to get value_counts() order 
Python :: Mixed Fractions in python 
Python :: get current scene file name godot 
Python :: how to create file organizer using python 
Python :: how to make an action repeat in python 
Python :: rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrooom 
Python :: multiclasshead 
Python :: light fm cold start problem 
Python :: jupyter notebook morse code francais 
Python :: how to push the element to array in python 
Python :: gnome-terminal stopped executing after python 3.6 is installed 
Shell :: remove steam from ubuntu 
Shell :: ubuntu list running services 
Shell :: uninstall k3s 
Shell :: ubuntu media codecs 
Shell :: check gnome version 
Shell :: notepad++ ubuntu 
Shell :: ubuntu disabling IPV6 
Shell :: restart rabbitmq service linux 
Shell :: install wps ubuntu 20.04 multilanguage 
Shell :: ubuntu 20.04 install skype 
Shell :: download filezilla in ubuntu 
Shell :: debian install killall 
Shell :: apple m1 pod install issue 
Shell :: python pip install r requirements txt 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =