方式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
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
if 'Alice' in d:
d.pop('Alice')
print(d)
else:
print("don't have Alice")
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
if 'Alice' in d:
d.pop('Alice')
print(d)
else:
print("don't have Alice")
2023-11-28
最新回答 / weixin_慕仰3352044
d = { 'Alice': 45, 'Bob': 60, 'Candy': 75, 'David': 86, 'Ellena': 49}names = ['Alice', 'Bob', 'Candy', 'Mimi', 'David']for item in names: print('{} score:{}'.format(item,d.get(item)))
2023-11-28
最新回答 / 翎栋
7-1答案,你这不是已经写了么新来的Gaven同学成绩是86,请编写一个dict,把Gaven同学的成绩也加进去。<...code...>
d = { 'Alice': 45, 'Bob': 60, 'Candy': 75, 'David': 86, 'Ellena': 49}
d['Gaven'] = 86
print(d)
2023-11-28
i = 0
sum = 0
while True:
if i > 1000:
break
else:
if i % 2 == 0:
sum += i
i += 1
print(sum)
sum = 0
while True:
if i > 1000:
break
else:
if i % 2 == 0:
sum += i
i += 1
print(sum)
2023-11-23
最新回答 / weixin_慕UI4308435
num = 0 # 初始化num用于存放偶数和for i in range(0, 1001, 1): # 利用range从0开始循环到1001(不包含1001),每次递增1,循环到1001等同于i<=1000 if i % 2 != 0:# 如果i除以2的余数不为0则说明i不能被2整除,此时i的值为奇数 num += i # 将i的值存到num中 continue# 不能被整除则跳过当前循环print(num) # 输出num的值,也就是1000以内所有偶...
2023-11-22
num = 0 # 初始化num用于存放偶数和
for i in range(0, 1001, 1): # 利用range从0开始循环到1001,每次递增1,循环到1001等同于i<=1000
if i % 2 != 0: # 如果i除以2的余数不为0则说明i不能被2整除,此时i的值为奇数
continue # 不能被整除则跳过当前循环
num += i # 将i的值存到num中
print(num) # 输出num的值,也就是1000以内所有偶数的值
for i in range(0, 1001, 1): # 利用range从0开始循环到1001,每次递增1,循环到1001等同于i<=1000
if i % 2 != 0: # 如果i除以2的余数不为0则说明i不能被2整除,此时i的值为奇数
continue # 不能被整除则跳过当前循环
num += i # 将i的值存到num中
print(num) # 输出num的值,也就是1000以内所有偶数的值
2023-11-22
template = 'Life is {0},you need {1}'
result = template.format('short','python')
print(result)
template = 'Life is {s} , you need {p}'
short ='short'
python = 'python'
result = template.format(s =short , p = python)
print(result)
result = template.format('short','python')
print(result)
template = 'Life is {s} , you need {p}'
short ='short'
python = 'python'
result = template.format(s =short , p = python)
print(result)
2023-11-16