第一种:
L = range(100,1000)
print([m for m in L if str(m)[0] == str(m)[2]])
第二种:
print([m*100+n*10+m for m in range(1,10) for n in range(0,10)])
无需if哦。
L = range(100,1000)
print([m for m in L if str(m)[0] == str(m)[2]])
第二种:
print([m*100+n*10+m for m in range(1,10) for n in range(0,10)])
无需if哦。
2020-06-04
最赞回答 / 慕圣_lucky
有几点需要注意:1. 单行注释要么单独成一行 要么在程序语句最后面。 不能插入到程序语句中间。2. 多行注释,使用三对双引号。 例如: """ 注释内容 """
2020-06-03
先删除index(2)的话,则下一次python执行操作的时候bart的index即为(2)因此如果运营pop(3)的话则超出list的元素个数界限。将两个顺序颠倒删除即可解决。
2020-06-03
x1 = 1
d = 3
n=100
sum = 0
for x in range(1,n+1):
# print(x,x1)
sum += x1
# print(x,x1,sum)
x1 += d
x100 = x1-d
# print(x100)
s = "sum = {}".format(sum)
print(s)
d = 3
n=100
sum = 0
for x in range(1,n+1):
# print(x,x1)
sum += x1
# print(x,x1,sum)
x1 += d
x100 = x1-d
# print(x100)
s = "sum = {}".format(sum)
print(s)
2020-06-01
x1 = 1
d = 3
n = 100
for x in range(1,n+1):
# print(x,x1)
x1 += d
x100 = x1 - d
s = "x100 = {}".format(x100)
print(s)
d = 3
n = 100
for x in range(1,n+1):
# print(x,x1)
x1 += d
x100 = x1 - d
s = "x100 = {}".format(x100)
print(s)
2020-06-01
最赞回答 / 慕运维5037917
<...图片...>第一个是正确的,第二是是错误的,按照你这样写,对应的key:value和后面的没有隔开就会变成:key:valuekey:value,实际是key:value,key:value
2020-06-01