遍历数组:
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']
for planet in planets:
print(planet, end=' ') # print all on same line
遍历5次:
for i in range(5):
print("Doing important work. i =", i)
while循环:
i = 0
while i < 10:
print(i, end=' ')
i += 1
list:
squares = []
for n in range(10):
squares.append(n**2)
字符串:
planet = 'Pluto'
planet[0]
输出:
"{}, you'll always be the {}th planet to me.".format(planet, position)
字典:
numbers = {'one':1, 'two':2, 'three':3}
numbers['one']
网友评论