程序自动崩溃
assert 4>7
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
import random
while(1):
enter = raw_input("S 开始/Q 退出:")
if(enter =="Q"):
print "游戏退出"
break;
if(enter =="S"):
val = random.randint(0,101)
while(1):
num = int(raw_input("请输入0-100之间的数字:"))
if(num == val):
print "您赢利"
elif(num >val):
print "您猜大了"
else:
print "您猜小了"
dict1 = dict.fromkeys((1,2,3,4,5,6))
for key in dict1:
dict1[key] = key
print dict1
结果:
{1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6}
for key,val in dict1.iteritems():
print key, val
结果:
1 1
2 2
3 3
4 4
5 5
6 6
si = [x+1 for x in range(10)]
>>> si
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> si = [x+1 for x in range(10) if(x>6)]
>>> si
[8, 9, 10]
>>> [(x,y,z) for x in range(2) for y in range(2) for z in range(2)]
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
>>> world1 = [[world,len(world)] for world in str1.split()]
>>> world1
[['welcome', 7], ['to', 2], ['pyont', 5], ['world', 5]]
区别:
列表解析器中是括号,而元组列表是小括号