본문 바로가기

파이썬 4장 정리- if문

조건문 Conditional Statements


* if 문


if 조건1:

body

body

elif 조건2:

body

body

else:

body



>>> x = int(input("Please enter an integer: "))
Please enter an integer: 42
>>> if x < 0:
...     x = 0
...     print('Negative changed to zero')
... elif x == 0:
...     print('Zero')
... elif x == 1:
...     print('Single')
... else:
...     print('More')
...
More


elif

- else if 줄임말. - 과도한 들여쓰기를 피하는데 유용. (過剰なインデントを避けるのに役立ちます)

- else와 함께 부가적인 부분,

- 다른 언어들의 switch, case 문을 대신 함.



---------------------------------------------------


* 간단 로그인 애플리케이션만들기 - input / output 연습




in_id = input("Id를 입력해주세요.\n")


real_park = 'psk'

real_an ="aby"


if real_park == in_id:

    print("hello!, Park")

elif real_an == in_id:

    print("hello!, An")

else:

    print("who are you?")




* 결과 :