“Kasing pertandingan Python” Kode Jawaban

Python Case Case

a = 15
match a:
  case 15:
    print ("fifteen")
  case  16:
    print ("sixteen")
BGOPC

Kasing pertandingan Python

x = 4

# x is the variable to match
match x:

    # if x is 0
    case 0:
        print("x is zero")

    # case with if-condition
    case 4 if x % 2 == 0:
        print("x % 2 == 0 and case is 4")

    # Empty case with if-condition
    case _ if x < 10:
        print("x is < 10")

    # default case(will only be matched if the above cases were not matched)
    # so it is basically just an else:
    case _:
        print(x)



# WHAT THE CODE WOULD LOOK LIKE IF IT DIDN'T USE MATCH/CASE

x = 4

if x == 0:
	print("x is zero")
elif x == 4 and x % 2 == 0:
	print("x % 2 == 0 and case is 4")
elif x < 10:
	print("x is < 10")
else:
	print(x)
Defeated Deer

Jawaban yang mirip dengan “Kasing pertandingan Python”

Pertanyaan yang mirip dengan “Kasing pertandingan Python”

Lebih banyak jawaban terkait untuk “Kasing pertandingan Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya