반응형
x = 28
if x < 0:
print('x < 0') # executes only if x < 0
elif x == 0:
print('x is zero') # if it's not true that x < 0, check if x == 0
elif x == 1:
print('x == 1') # if it's not true that x < 0 and x != 0, check if x == 1
else:
print('non of the above is true')
name = "John"
if name == "John": # Print True if name is equal to "John" and False otherwise.
print(True)
else:
print(False)
산출물 (Output)
non of the above is true
True
* else statement는 if statement를 보완합니다.
"elif" keyword는 "else if"의 줄임 말입니다.
반응형
'Python 배우기' 카테고리의 다른 글
for_string.py (0) | 2016.03.09 |
---|---|
for_loop.py (0) | 2016.03.09 |
if_statement.py (0) | 2016.03.08 |
boolean_order.py (0) | 2016.03.08 |
boolean_operators.py (0) | 2016.03.08 |
댓글