[Python] Conditional Statement (조건문)
※ 조건문 (IF)
- :(콜론)을 사용하여 조건을 나눔
■ 기본 구조
> if condition:
<statement>
<statement>
...
elif condition:
<statement>
<statement>
...
else:
<statement>
...
□ pass
- 조건문에서 코드를 실행하지 않고 넘어가고 싶을 때 사용
> a = 1
> if a >= 0:
pass
else:
print("AA")
# 아무것도 출력 X
■ key points
- :(콜론) 사용에 주의
- 조건의 예외사항에 주의 (보통 edge case에서 주로 발생)
- list의 처음과 끝의 원소에 indexing 하는 경우 (bounday condition)
□ 비교 연산 / 논리 연산
a == b
a != b
a > b
a < b
a >= b
a <= b
# A and B
A and B
# A or B
A or B
# not A
not A
댓글남기기