4.1. if 문법

ifStatements


Perhaps the most well-known statement type is the if statement. For example:
아마도 if문법은 가장 흔하게 알려져 있는 문법일 것이다.

  >>> 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

There can be zero or more elif parts, and the else part is optional. The keyword ‘elif‘ is short for ‘else if’, and is useful to avoid excessive indentation. An if ... elif ... elif ... sequence is a substitute for the switch or case statements found in other languages.
elif는 'else if'의 줄임말로, 없어도 되고 여러개를 써도 된다. else는 넣고 싶으면 넣고 넣기 싫으면 안 넣어도 된다.(선택사항이다.) elif는 과도한 들여쓰기를 막는데 유용하다. ifelif로 이루어진 하나의 시퀀스(흐름, 덩어리)는 다른 프로그래밍 언어에서 스위치 또는 케이스라 불리는 문법과 같다.

results matching ""

    No results matching ""