-
[Python tutorial] 12. Control flow, If...else코딩/Python 2022. 12. 21. 17:14728x90
if ... elif ... else
a = 200 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b") # a is greater than b
Short Hand If
if a > b: print("a is greater than b")
Short Hand If ... Else
Ternary Operators or Conditional Expressions
a = 330 b = 330 print("A") if a > b else print("=") if a == b else print("B") # multiful else
and
a = 200 b = 33 c = 500 if a > b and c > a: print("Both conditions are True")
Or
a = 200 b = 33 c = 500 if a > b or a > c: print("At least one of the conditions is True")
Nested If
x = 41 if x > 10: print("Above ten,") if x > 20: print("and also above 20!") else: print("but not above 20.")
pass Statement
if statements cannot be empty
pass statement to avoid getting an errora = 33 b = 200 if b > a: pass
728x90'코딩 > Python' 카테고리의 다른 글
[Python tutorial] 14. Functions (0) 2022.12.21 [Python tutorial] 13. Control flow, Loop, Iterator (0) 2022.12.21 [Python tutorial] 11. Operators (0) 2022.12.21 [Python tutorial] 10. Data type - Dictionary (0) 2022.12.21 [Python tutorial] 9. Data type - Sets (0) 2022.12.21