Python代码实现题型

1.写出print()输出值

a = [1, 2, 3, 4, 5]
# [1, 3, 5]
print(a[::2])
# [4, 5]
print(a[-2:])

2.写出调用函数的输出结果

def fn(x, lst=[]):
    for i in range(x):
        lst.append(i * i)
    print(lst)

# [0, 1]
fn(2)

# [3, 2, 1, 0, 1, 4]
fn(3, [3,2,1])

# [0, 1, 0, 1, 4]
fn(3)

3.写出print()输出值

class Person:
    name = []
    
p1 = Person()
p2 = Person()
p1.name.append('Andy')

print(p1.name)  # ['Andy']
print(p2.name)  # # ['Andy']
print(Person.name)  # # ['Andy']

4.写出print()输出值

def extendList(val, lst=[]):
    lst.append(val)
    re

你可能感兴趣的:(面试题,python,开发语言)