http://docs.python.org/tutorial/controlflow.html#if-statements
Perhaps the most well-known statement type is the if statement. For example:
>>> x = int(raw_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 orcase statements found in other languages.
'Programming' 카테고리의 다른 글
[Python] Python Debugger - pdb 기본 사용법 (0) | 2012.05.29 |
---|---|
Python Mapping Types — dict (0) | 2012.05.29 |
How do I generate random numbers in Python? (0) | 2012.05.29 |
Python is Cool (and Perl is not), Especially for C/C++ Programmers (0) | 2012.05.29 |
Is it possible to implement a Python for range loop without an iterator variable? (0) | 2012.05.29 |