rexwashburn
1/23/2019 - 12:06 PM

For ループ : range

#!/usr/local/bin/python3.4
# coding:utf-8

print("Content-Type: application/json; charset=UTF-8\r\n")

count = 0
for x in range(5):
  print(x)
  count += 1
print("Loop count:", count, "\n")
# 0
# 1
# 2
# 3
# 4
# Loop count: 5 

list = []
for x in range(0, 10, 2):
  print(x)
  list.append(x)
print("List", list, "\n")
# 0
# 2
# 4
# 6
# 8
# List [0, 2, 4, 6, 8] 

tuple = (0,)
for x in range(0, 10, 2):
  print(x)
  tuple = tuple + (x, x+1)
print("Tuple", tuple, "\n")
# 0
# 2
# 4
# 6
# 8
# Tuple (0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)