if
variableName = True
if variableName:
print('value')
実行結果
value
else
variableName = False
if variableName:
print('value1')
else:
print('value2')
実行結果
value2
else if
variableName = 2
if variableName == 1:
print('value1')
elif variableName == 2:
print('value2')
else:
print('value3')
実行結果
value2
複数
def function_name(argument):
if argument in (1, 2):
print('value')
function_name(1)
function_name(2)
function_name(3)
実行結果
value
value
match
param = "v2"
match param:
case "v1":
print("1")
case "v2":
print("2")
_:
print("else")
実行結果
2
param = ["value1", "value2", "value3"]
match param:
case v1:
print("v1")
case v1, v2:
print("v1,v2")
case v1, v2, v3:
print("v1,v2,v3")
case v1, v2, v3, v4:
print("v1, v2, v3, v4")
実行結果
v1,v2,v3