s = set(['Adam','adam','bart','Bart'])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2015-09-25
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
2015-09-25
修改如下:
age = 20
if (age >= 6 and age =< 20):
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
age = 20
if (age >= 6 and age =< 20):
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
2015-09-25
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if(n>20):
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if(n>20):
break
print sum
2015-09-25
先删除第三个,在删除第二个,即调换两个输出语句的位置。;或者删除第二个,因为已经调整位置了,再删除一次第二个就可以了。即两次pop(2).
2015-09-25
在第一个print语句中,a = 'python',a为True,结果必为True,所以输出helo,python.
第二个print语句中,b = '',结果取决于后面的'world',所以输出hello,world
第二个print语句中,b = '',结果取决于后面的'world',所以输出hello,world
2015-09-25
t = ('a', 'b', ['A', 'B'])
t = list(t)
t[2] = ('a','b')
t = tuple(t)
print t
t = list(t)
t[2] = ('a','b')
t = tuple(t)
print t
2015-09-24
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
print L
L.pop(2)
print L
要分开因为第一删了之后,列表中的位置会发生改变
L.pop(2)
print L
L.pop(2)
print L
要分开因为第一删了之后,列表中的位置会发生改变
2015-09-24
print r'''"to be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2015-09-24