, 。
, , , Python , if :
age = 20
if age >= 18:
print('your age is', age)
print('adult')
Python , if True, print , , 。
if else , , if False, if , else :
age = 3
if age >= 18:
print('your age is', age)
print('adult')
else:
print('your age is', age)
print('teenager')
:。
, elif :
age = 3
if age >= 18:
print('adult')
elif age >= 6:
print('teenager')
else:
print('kid')
elif else if , elif, if ××× :
if :
elif :
elif :
else:
if , , True, ,
elif else, , teenager:
age = 20
if age >= 6:
print('teenager')
elif age >= 18:
print('adult')
else:
print('kid')
if , :
if x:
print('True')
x 、 、 list , True, False。
input
。 input() , , :
birth = input('birth: ')
if birth < 2000:
print('00 ')
else:
print('00 ')
1982, :
Traceback (most recent call last):
File "", line 1, in
TypeError: unorderable types: str() > int()
input() str,str , str 。Python int()
:
s = input('birth: ')
birth = int(s)
if birth < 2000:
print('00 ')
else:
print('00 ')
, 。 , abc ? :
Traceback (most recent call last):
File "", line 1, in
ValueError: invalid literal for int() with base 10: 'abc'
int() , 。
? 。