L = range(0, 10)
print([x*100 + y*10 + z for x in L for y in L for z in L if x == z and x > 0])
print([x*100 + y*10 + z for x in L for y in L for z in L if x == z and x > 0])
2020-02-06
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2020-02-06
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k in d:
print k,':',d[k]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k in d:
print k,':',d[k]
2020-02-06
已采纳回答 / 我不会起名字
<...图片...>以下是我的个人理解,希望会对题主有帮助。左侧图示的代码可以达到题主想要的目的。这里要明确两个概念:continue和break的: break:用来跳出整个循环 continue:跳过本次...
2020-02-05
最新回答 / qq_慕仙9465210
sum = 0x = 1n = 1while True: sum+=2**(n-1) #x*=2 n+=1 if n>20: break print sum<...code...>
2020-02-05
sum = 0
x = 1
while x<100:
print x
x=x+2
sum=sum+x
print sum
x = 1
while x<100:
print x
x=x+2
sum=sum+x
print sum
2020-02-05