019
0.yes1.[]
2.no
3.
a.list1;list1[-1]
4.
5.1,3,5
6.1,2,3,4,5
7.?
dds
0.
nums =
target = 9
# 获取 nums 的长度,并将结果存放到 n 变量中 #
n = len(nums)
for i in range(n):
for j in range(i+1,n):
if nums + nums == target:
print('[',i,',',j,']')
1.
nums = []
while 1:
temp = input('input a intager(stop with stop):')
if temp == 'stop':
break
else:
nums +=
target = int(input('input the target number:'))
n = len(nums)
for i in range(n):
for j in range(i+1,n):
if nums + nums == target:
print('[',i,',',j,']')
2.import random
nums = []
i = 1
while i <= 10000:
nums +=
i += 1
target = int(input('input the target number:'))
n = len(nums)
for i in range(n):
for j in range(i+1,n):
if nums + nums == target:
print('[',i,',',j,']')
****************************************
2. 你知道什么是匿名列表吗
答:如果我们创建了一个列表,但没有将其赋值给变量名,这就是一个匿名列表。
解析:由于没有名字,将导致列表创建完也没办法再次访问到它,所以是一个看上去比较 “鸡肋” 的东东。
3.答:list1 和 list1[-1]
7.
>>> list1 = list1[:2] + list2 + list1
>>> list1
-----------------------
0.
print()
1. 順帶一提,匿名列表還有其它用途,可以節省代碼空間,不完全只是“雞肋”{:5_109:}{:5_109:}
如:
# 九九乘法表 (9x9 Times table)
[[, print()] for i in range(9, 0, -1)] 9 * 9 = 81 9 * 8 = 72 9 * 7 = 63 9 * 6 = 54 9 * 5 = 45 9 * 4 = 36 9 * 3 = 27 9 * 2 = 18 9 * 1 =9
8 * 8 = 64 8 * 7 = 56 8 * 6 = 48 8 * 5 = 40 8 * 4 = 32 8 * 3 = 24 8 * 2 = 16 8 * 1 =8
7 * 7 = 49 7 * 6 = 42 7 * 5 = 35 7 * 4 = 28 7 * 3 = 21 7 * 2 = 14 7 * 1 =7
6 * 6 = 36 6 * 5 = 30 6 * 4 = 24 6 * 3 = 18 6 * 2 = 12 6 * 1 =6
5 * 5 = 25 5 * 4 = 20 5 * 3 = 15 5 * 2 = 10 5 * 1 =5
4 * 4 = 16 4 * 3 = 12 4 * 2 =8 4 * 1 =4
3 * 3 =9 3 * 2 =6 3 * 1 =3
2 * 2 =4 2 * 1 =2
1 * 1 =1
页:
[1]