阅读下面代码 ,分析其执行结果【 】。x = list(range(20))for i in range(len(x)): x.pop(i)
A: 结果为None
B: []
C: [1,2,3,4,5,6,7,8,9,10]
D: 异常报错
A: 结果为None
B: []
C: [1,2,3,4,5,6,7,8,9,10]
D: 异常报错
举一反三
- 中国大学MOOC: 阅读下面代码 ,分析其执行结果【 】。x = list(range(20))for i in range(len(x)): x.pop(i)
- 下面说法错误的是( )。知识点:列表推导式 A: dict([(x, x**2) for x in range(6)]) 创建的字典是{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25} B: [[x*3+y for y in range(1,4)] for x in range(3)] 创建的是二维列表 [[1, 2, 3], [4, 5, 6], [7, 8, 9]] C: number = [-2, 4, 6, -5]string = 'ab'z = [(i, j) if i>0 else (-i, j) for i in number for j in string]这段代码创建的列表为[(2, 'a'), (2, 'b'), (4, 'a'), (4, 'b'), (6, 'a'), (6, 'b'), (5, 'a'), (5, 'b')] D: ' '.join([i for i in range(1,11)])的运算结果为字符串'1 2 3 4 5 6 7 8 9 10'
- set1 = {x for x in range(10)} print(set1) 以上代码的运行结果为? A: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} B: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10} C: {1, 2, 3, 4, 5, 6, 7, 8, 9} D: {1, 2, 3, 4, 5, 6, 7, 8, 9,10}
- set1 = {x for x in range(10) if x%2!=0} print(set1) 以上代码的运行结果为? A: {1, 3, 5, 7, 9} B: {1, 3, 5, 7} C: {3, 5, 7, 9} D: {3, 5, 7}
- set1 = {x for x in range(10) if x%2!=0} set1.remove(1) print(set1) 以上代码的运行结果为? A: {1, 3, 5, 7, 9} B: {1, 3, 5, 7} C: {3, 5, 7, 9} D: {3, 5, 7}