请问以下情况是什么原因呢?这数字也是唯一的呀?
>>> d={
32:'asd',
89:'zxc',
87:'dsw'
}
>>> for key in d:
print key +':',d[key]
Traceback (most recent call last):
File "<pyshell#19>", line 2, in <module>
print key +':',d[key]
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>
>>> d={
32:'asd',
89:'zxc',
87:'dsw'
}
>>> for key in d:
print key +':',d[key]
Traceback (most recent call last):
File "<pyshell#19>", line 2, in <module>
print key +':',d[key]
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>
2016-07-04
# -*- coding: utf-8 -*-
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
for x in d:
if d.get(x)==95:
print x
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
for x in d:
if d.get(x)==95:
print x
2016-07-04
已采纳回答 / qq_城南以南_03468985
type = "shout" 这样写说明它是一个默认参数 当调用getTalk()时 你没有传入 type的形参 系统默认给type赋值为“shout” 当调用getTalk("whisper") 时 传入了形参 则将"whisper"赋值给type 你的理解是对的
2016-07-04
x1 = 1
d = 3
n = 100
x100 = x1 + 3*99
s = 100*(x1 + x100)/2
print s
d = 3
n = 100
x100 = x1 + 3*99
s = 100*(x1 + x100)/2
print s
2016-07-03
move(n,a,b,c)可以理解为将n层的汉诺塔通过b,从a移到c
递归部分:
如果把n-1层看做整体,总共就需要三步。
1:把n-1整体移到借助c柱子,从a移到b. move(n-1,a,c,b)
2: 把最下面的圆盘借助b柱子,从a移到c. print a-->c
3: 把n-1整体移到借助a柱子,从b移到c. move(n-1,b,a,c)
递归结束部分:
n=1时,直接从a柱移到c柱
递归部分:
如果把n-1层看做整体,总共就需要三步。
1:把n-1整体移到借助c柱子,从a移到b. move(n-1,a,c,b)
2: 把最下面的圆盘借助b柱子,从a移到c. print a-->c
3: 把n-1整体移到借助a柱子,从b移到c. move(n-1,b,a,c)
递归结束部分:
n=1时,直接从a柱移到c柱
2016-07-03