Match case statement in python

 x = int(input("Enter the value of x:"))

 # x is the variable to match

match x:

  # if x is o

   case 0:

       print("x is zero")

  # case with if-condition

   case 4:

    print("case is 4")

   case _ if x!=90:

    print(x, "is not 90")

   case _ if x!=80:

     print(x, "is not 80")

   case _ if x!=90:

     print(x, "is not 90")

   case _ if x!=80:

     print(x, "is not 80")

   case _: 

     print(x)

Result: Enter the value of x:56
56 is not 90
Enter the value of x:0
x is zero

Comments

Popular posts from this blog

According to Data Science Topic-13 Modules

Functions in Python:

According to Data Science Topic-12 If else program examples