最贊回答 / weixin_慕村6176323
.format 的意思是指可以任意替代某一個位置例:第一種<...code...>第二種<...code...>注:{}代表空字典常常與.format連用
2022-08-02
最新回答 / 久見遠坂
為什么要加那么多判斷導致代碼冗余這樣就行了:
tatol?tatols?i?tatol?tatol?itatol ????i?tatols?tatols?itatols ????R?R
2022-08-01
最贊回答 / qq_慕粉4217309
num = 5while True:? ? if num >= 90:? ? ? ? break? ? num = num + 2print(num)來試試這個
2022-07-28
最贊回答 / qq_慕粉4217309
L = [95.5, 85, 59, 66, 72]L.sort()print(L)print(L[-3:5])這樣就好了,因為【:】是從左往右看的
2022-07-28
def sub_sum(L):
result_odd=[]
result_even=[]
for i in L:
if i%2==1:
result_odd.append(i)
else:
result_even.append(i)
return sum(result_odd),sum(result_even)
L = [1, 3, 5, 7, 9]
print(sub_sum(L))
result_odd=[]
result_even=[]
for i in L:
if i%2==1:
result_odd.append(i)
else:
result_even.append(i)
return sum(result_odd),sum(result_even)
L = [1, 3, 5, 7, 9]
print(sub_sum(L))
2022-07-26
def square_of_sum(L):
result=0
for i in L:
result=result+i*i
return result
L = [1, 3, 5, 7, 9, 11]
print(square_of_sum(L))
result=0
for i in L:
result=result+i*i
return result
L = [1, 3, 5, 7, 9, 11]
print(square_of_sum(L))
2022-07-26
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
same=[]
print(s1.isdisjoint(s2))
for i in s1:
for j in s2:
if i==j:
same.append(i)
print(same)
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
same=[]
print(s1.isdisjoint(s2))
for i in s1:
for j in s2:
if i==j:
same.append(i)
print(same)
2022-07-26
a是字符所以a=True,所以a or 'world'=a 根據(jù)與運算法則返回world結(jié)果是hello,python
b是空字符串所以b=False,所以b or 'world'根據(jù)or運算法返回world,所以結(jié)果是hello,world
b是空字符串所以b=False,所以b or 'world'根據(jù)or運算法返回world,所以結(jié)果是hello,world
2022-07-26
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for i in L:
if i in S:
S.remove(i)
else:
S.add(i)
print(S)
S = set([1, 3, 5, 7, 9, 11])
for i in L:
if i in S:
S.remove(i)
else:
S.add(i)
print(S)
2022-07-25
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names_set = set(names)
print(names_set)
x="alice"
for i in names_set:
if x.capitalize()==i:
print("True")
names_set = set(names)
print(names_set)
x="alice"
for i in names_set:
if x.capitalize()==i:
print("True")
2022-07-25
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for i in d:
for j in d[i]:
print(i,j)
for i in d:
for j in d[i]:
print(i,j)
2022-07-22
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
print(d.items())
for i,value in d.items():
print(i,value)
print(d.items())
for i,value in d.items():
print(i,value)
2022-07-22
最贊回答 / weixin_精慕門7014924
sum是你可以自己指定的變量(它甚至可以不叫sum,只要是其他任意符合python命名規(guī)范的變量名都可以)。在求和時,因為0加上任何數(shù)都不會改變其值,所以將sum設(shè)置為0是可行的(當然設(shè)置為1也是可行的,得到的結(jié)果是一樣的);在求乘積時,當然不可以乘0,所以就直接設(shè)sum的初始值為1啦。一句話概括,就是你想讓sum是什么值它就可以是什么值,只要保證結(jié)果正確。
2022-07-20
# Enter a code
count = 10;
this_num = 0;
while this_num < count:
print(this_num)
this_num+=1
count = 10;
this_num = 0;
while this_num < count:
print(this_num)
this_num+=1
2022-07-19