2018年6月27日之二

citys = ['wuxi', 'changzhou', 'suzhou']
for city in citys:
    print(city)
wuxi
changzhou
suzhou
citys = ['wuxi', 'changzhou', 'suzhou']
for city in citys:
    print("Hello,", city, "!")
Hello, wuxi !
Hello, changzhou !
Hello, suzhou !
citys = ['wuxi', 'changzhou', 'suzhou']
for city in citys:
    print("Hello,", city, "!")
print("I love citys")
Hello, wuxi !
Hello, changzhou !
Hello, suzhou !
I love citys
for i in range(1, 21):
    print(i)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
nums = [num for num in range(1, 21)]
print(nums)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
nums = [num for num in range(1, 1000001)]
print(max(nums))
print(min(nums))
print(sum(nums))
1000000
1
500000500000
nums = [num for num in range(1, 21, 2)]
print(nums)
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
nums = [num for num in range(3, 31, 3)]
print(nums)
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
nums = [num**3 for num in range(1, 11)]
print(nums)
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
citys = ['wuxi', 'changzhou', 'yancheng', 'nanjing', 'shanghai']
print(citys[:2])
print(citys[1:4])
print(citys[-3:])
anot_citys = citys[:]
citys.append('suzhou')
print(citys)
print(anot_citys)
['wuxi', 'changzhou']
['changzhou', 'yancheng', 'nanjing']
['yancheng', 'nanjing', 'shanghai']
['wuxi', 'changzhou', 'yancheng', 'nanjing', 'shanghai', 'suzhou']
['wuxi', 'changzhou', 'yancheng', 'nanjing', 'shanghai']

猜你喜欢

转载自www.cnblogs.com/2018jason/p/9235206.html
今日推荐