直接使用 get 方法如果找不到默认返回 None 的特性,代码如下。
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for name in names :
print(d.get(name))
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for name in names :
print(d.get(name))
2023-12-13
最新回答 / weixin_慕无忌2350060
if not isinstance(x,int) or not isinstance(x,float):这里应该用and,否则任何类型进去都是true
2023-12-12
最新回答 / 慕UI2375754
不需要的,sum相当于一个无限大的容器,sum = sum+x,相当于把原本sum容器里的东西加上x再一起返回sum容器里面,sum1=sum+x应该理解为把 原本sum容器里的东西加上x放进sum1这个容器
2023-12-08
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.''')
2023-12-07
最赞回答 / 時頌望見
元组T = (1, 'CH', [3, 4])内的这几个元素的类型是不能改变的,[3,4]是T的一个元素,并且不是元组,所以它的值可变;但是它的类型是不可变的
2023-12-04
方式1:
template='life {0}, {1} Python.'
a='is short'
b='you need'
result=template.format(a,b)
print(result)
方式2:
template='life {o}, {t} Python.'
one='is short'
two='you need'
result=template.format(o=one,t=two)
print(result)
template='life {0}, {1} Python.'
a='is short'
b='you need'
result=template.format(a,b)
print(result)
方式2:
template='life {o}, {t} Python.'
one='is short'
two='you need'
result=template.format(o=one,t=two)
print(result)
2023-11-30