小例二
阿新 • • 發佈:2018-06-21
gif splay AS style python odin lsi .... int
一: 已知:元組 a = (1,2,3) 利用list方法,輸出下面的結果:
(1,2,4)
1 #! /urs/bin/evn python 2 # -*- coding:utf-8 -*- 3 4 a = (1, 2, 3) 5 mylsit = list(a) 6 mylsit[2] = 4 7 a = tuple(mylsit) 8 print(a, type(a))View Code
二: 利用列表推導完成下面習題:
1 輸出結果:[1 love python,2 love python,3 love python,.... 10 love python]
1 myslit = ["View Code%s love python" % i for i in range(1, 11)] 2 print(myslit)
結果:
1 [‘1 love python‘, ‘2 love python‘, ‘3 love python‘, ‘4 love python‘, ‘5 love python‘, ‘6 love python‘, ‘7 love python‘, ‘8 love python‘, ‘9 love python‘, ‘10 love python‘]View Code
2 輸出結果:[(0,0),(0,2),(2,0),(2,2)]
1 mylist = [(x, y) forView Codx in range(0, 3, 2) for y in range(0, 3, 2)] 2 print(mylist) 3 4 5 結果: 6 [(0, 0), (0, 2), (2, 0), (2, 2)]
小例二