Python计算1到100的加和

print(sum(range(1,101)))

print(sum([x for x in range(1,101)]))

sum_value = 0
for i in range(1,101):
    sum_value += i
print(sum_value)

结果:
5050
5050
5050
posted @ 2023-08-23 17:39  高宏宇  阅读(115)  评论(0编辑  收藏  举报