age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2020-03-26
#Enter a code
num1=45678
num2=0x12fd2
sum=num1+num2
print sum
str='learn Python in mooc'
print str
print 100<99
print 0xff==255
num1=45678
num2=0x12fd2
sum=num1+num2
print sum
str='learn Python in mooc'
print str
print 100<99
print 0xff==255
2020-03-25
t=('a','b',('A','B'))
2020-03-25
L = []
n = 1
while True:
L.append(n**2)
n = n + 1
if(n > 100):
break
print sum(L) # ==> 338350
n = 1
while True:
L.append(n**2)
n = n + 1
if(n > 100):
break
print sum(L) # ==> 338350
2020-03-25
print [int(str(x)+str(y)+str(z)) for x in range(1,10) for y in range(0,10) for z in range(0,10) if x == z]
2020-03-23
print 45678 + 0x12fd2
print 'Learn Python in imooc'
print 100<99
print 0xff==255
print 'Learn Python in imooc'
print 100<99
print 0xff==255
2020-03-23
for x in [1,2,3,4,5,6,7,8]:
for y in [2,3,4,5,6,7,8,9]:
if x < y:
print x,y
for y in [2,3,4,5,6,7,8,9]:
if x < y:
print x,y
2020-03-23
特别注意: 这一系列条件判断会从上到下依次判断,如果某个判断为 True,执行完对应的代码块,后面的条件判断就直接忽略,不再执行了。
2020-03-23
s = set (['Adam','Lisa','Bart','Paul'])
print ('Adam'.capitalize() in s)
print ('bart'.capitalize() in s)
print ('Adam'.capitalize() in s)
print ('bart'.capitalize() in s)
2020-03-22
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d.get(key)
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d.get(key)
2020-03-20