Python 在线测试
以下测验提供与Python相关的多项选择题(MCQ)。 您必须阅读所有给定的答案并单击正确的答案。 如果您不确定答案,则可以使用“ Show Answer按钮Show Answer 。 您可以使用“ Next Quiz按钮在Next Quiz中检查新的问题集。
Answer : A
说明 (Explanation)
列表可以包含其他列表值。
因此,在这个问题中,S [0]给出['他','卖'],S [0] [1]给出'卖',S [0] [1] [1]给'e'。
请记住,python中的索引以'0'开头。
问题2 - 以下代码的输出是什么 -
[ (a,b) for a in range(3) for b in range(a) ]
Answer : D
说明 (Explanation)
这是嵌套for循环。 first for循环的输出将是下一循环的值。
问3 - 以下代码的输出是什么 -
print('hijk'.partition('ab'))
Answer : C
说明 (Explanation)
由于给定字符串中没有分隔符,因此输出是相同的字符串。
问4 - 以下代码的输出是什么 -
class Count:
def __init__(self, count=0):
self.__count=count
a=Count(2)
b=Count(2)
print(id(a)==id(b), end = '' '')
c= ''hello''
d= ''hello''
print(id(c)==id(d))
Answer : B
说明 (Explanation)
具有相同内容的对象在python库中共享相同的对象,但对于自定义的不可变类不是这样。
Answer : A
说明 (Explanation)
listname.insert(x,y)方法用于在列表中的某个位置插入项。 x定义元素添加的位置,y定义要添加到列表中的元素。
问题6 - 以下代码的输出是什么?
class P:
def __init__(self):
self.__x=100
self.y=200
def print(self):
print(self.__x, self.y)
class C(P):
def __init__(self):
super().__init__()
self.__x=300
self.y=400
d = C()
d.print()
Answer : B
说明 (Explanation)
在上面的代码中,x是在类P中声明的私有变量。因此,在继承类P的类C中,不能更改x的值。但是y不是私有变量,因此可以更改其值。
问题7 - 代码是什么?
def rev_func(x,length):
print(x[length-1],end='' '')
rev_func(x,length-1)
x=[11, 12, 13, 14, 15]
rev_func(x,5)
Answer : D
说明 (Explanation)
在rev_func的print语句中,我们使用list x的索引值。 我们减去函数长度的值,因为它成为print语句中x的索引。