[python] 조건문 if, elif, else, and, or, not

iberis2·2024년 4월 2일

python

목록 보기
3/6

python 에서 조건문 사용 방법은 javacscript 의 switch, case 문처럼 : 를 조건의 마지막에 적고 본문을 한 칸 들여쓰면 된다.

  • else if 대신 elif 를 사용한다
  • and, or 연산자를 사용해 조건을 혼합할 수 있다.
  • 조건문 안에 조건문을 중첩해서 사용할 땐 들여쓰기가 중요하다
num = 100
boolean = True

if num > 50:
  print('num is over 50')
  if boolean: # 두 번째 조건문
    print('second conditional')
elif num >= 50 and num < 70:
  print('num is between 50 and 70')
elif num >= 70
  print('num is over 70')
else:
  print('num is under 50')
profile
자동화와 기록으로 더 효율적으로 일하는 으른 개발자가 되려고 합니다.

0개의 댓글