d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
n=0
for key,value in d.items():
n=n+1
print(n)
n=0
for key,value in d.items():
n=n+1
print(n)
2022-03-04
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for key in d:
p=d[key]
n=0
while n <3:
print(key,p[n])
n=n+1
或
for key,v in d.items():
n=0
while n <3:
print(key,v[n])
n=n+1
for key in d:
p=d[key]
n=0
while n <3:
print(key,p[n])
n=n+1
或
for key,v in d.items():
n=0
while n <3:
print(key,v[n])
n=n+1
2022-03-04
最贊回答 / 慕斯卡8373086
def square_of_sum(L):? ? result = []? ? for i in L:? ? ? ? result.append(i*i)? ? return resultd = [1,2,3,4,5]r = square_of_sum(d)print(r)我是這樣寫(xiě)的
2022-03-03
已采納回答 / 小穎April
因?yàn)橛兄睾戏祷豧alse,所以flag的值為假,not flag就為真,所以if not flag就是為了進(jìn)入這個(gè)條件判斷,接下來(lái)的操作就是打印重復(fù)元素了
2022-03-03
提供給大家參考
先把數(shù)據(jù)改成list,再改回tuple
# Enter a code
T = (1, 'CH', [3, 4])
print T
T = list(T)
print T
T[2] = tuple(T[2])
print T
T = tuple(T)
print T
先把數(shù)據(jù)改成list,再改回tuple
# Enter a code
T = (1, 'CH', [3, 4])
print T
T = list(T)
print T
T[2] = tuple(T[2])
print T
T = tuple(T)
print T
2022-03-03
最贊回答 / 金思錄
答案里的item是隨意定義的一個(gè)變量名,你可以把item換成A、B、c、d都可以。for item in L #將L中的每個(gè)元素依次賦予item這個(gè)變量,相當(dāng)于第一次循環(huán)item=1,第二次循環(huán)item=2.....????if item in S:? #如果item的值在S中? ? ? ? S.remove(item) #那么就在S中移除item的值,那么在第一次循環(huán)中可以看到1確實(shí)在S中,所以在S中移除1????else:? ??#如果item的值不在S中? ? ? ??S.add(item)??#那...
2022-03-03
# Enter a code
students = ['Alice', 'Bob', 'Candy', 'David']
students[0] = 'Ellena'
print(students)
students.insert(1,'Alice')
print(students)
students.pop(2)
print(students)
students.append('Bob')
print(students)
students = ['Alice', 'Bob', 'Candy', 'David']
students[0] = 'Ellena'
print(students)
students.insert(1,'Alice')
print(students)
students.pop(2)
print(students)
students.append('Bob')
print(students)
2022-03-01
L=[95.5,85,59,66,72]
length=0;
i=0
j=0
for l in L:
length+=1
temp =0;
while i < length-1:
j = i+1
while j < length:
if L[i]<L[j]:
temp = L[i]
L[i] = L[j]
L[j] = temp
j+=1
i+=1
print(L[0],L[1],L[2])
length=0;
i=0
j=0
for l in L:
length+=1
temp =0;
while i < length-1:
j = i+1
while j < length:
if L[i]<L[j]:
temp = L[i]
L[i] = L[j]
L[j] = temp
j+=1
i+=1
print(L[0],L[1],L[2])
2022-02-27
s1='ABC'
s2='123'
s3='xyz'
for s11 in s1:
for s22 in s2:
for s33 in s3:
print(s11+s22+s33)
s2='123'
s3='xyz'
for s11 in s1:
for s22 in s2:
for s33 in s3:
print(s11+s22+s33)
2022-02-27
# coding: utf-8
s1 = '這是一句中英文混合的Python字符串:'
s2 = 'Hello World!'
print(s1+s2)
result = 's1{s2}'.format(s2='Hello World!')
print(result)
s1 = '這是一句中英文混合的Python字符串:'
s2 = 'Hello World!'
print(s1+s2)
result = 's1{s2}'.format(s2='Hello World!')
print(result)
2022-02-26
已采納回答 / 幕布斯8123072
第一行:定義變量d為初始dict對(duì)象,即:d={}第二行:往d里面添加一個(gè)數(shù)據(jù),結(jié)果為d={'Alice':[]}第三行:往d里面添加一個(gè)數(shù)據(jù),結(jié)果為d={'Alice':[], 'Bob':[]}第四行:往d里面添加一個(gè)數(shù)據(jù),結(jié)果為d={'Alice':[],?'Bob':[], 'Candy'=[]}
2022-02-25