8、python_range
range可以帮我们获取到一组数据. 通过for循环能够获取到这些数据.
s = "他轻轻地来,又悄悄的走了" for c in s: print(c)
- range()
for i in range(10): #从0开始,到10结束 print(i)
- 求:1-2+3-4.....+99-100=?
sum = 0 for i in range(1, 101): if i % 2 == 0: sum = sum - i else: sum = sum + i print(sum)
结果:-50