目录

Python 在线测试

以下测验提供与Python相关的多项选择题(MCQ)。 您必须阅读所有给定的答案并单击正确的答案。 如果您不确定答案,则可以使用“ Show Answer按钮Show Answer 。 您可以使用“ Next Quiz按钮在Next Quiz中检查新的问题集。

问题和解答

问题1 - 输出是什么 -

S = [['他','卖'],[90,28,43]]

S [0] [1] [1]

A - 'e'

B - 'i'

C - '90'

D - 'h'

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) ]

A - [ (1,0),(2,1),(3,2)]

B - [ (0,0),(1,1),(2,2)]

C - [(1,0),(2,1),(2,1)]

D - [ (1,0),(2,0),(2,1)]

Answer : D

说明 (Explanation)

这是嵌套for循环。 first for循环的输出将是下一循环的值。

问3 - 以下代码的输出是什么 -

print('hijk'.partition('ab'))

A - ('hijk', 'cd', ' ')

B - ('hijk')

C - ('hijk', ' ', ' ')

D - 名称错误

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))

A - True False

B - False True

C - False False

D - True True

Answer : B

说明 (Explanation)

具有相同内容的对象在python库中共享相同的对象,但对于自定义的不可变类不是这样。

问5 - 用什么命令在第3个位置的列表“L”中插入6?

A - L.insert(2,6)

B - L.insert(3,6)

C - L.add(3,6)

D - L.append(2,6)

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()

A - 300 400

B - 100 400

C - 100 200

D - 300 200

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) 

A - 程序运行正常,没有错误。

B - 程序显示15 14 13 12 11。

C - 程序显示11 12 13 14 15。

D - 程序显示15 14 13 12 11然后引发索引超出范围异常。

Answer : D

说明 (Explanation)

在rev_func的print语句中,我们使用list x的索引值。 我们减去函数长度的值,因为它成为print语句中x的索引。

问题8 - 在它们中选择正确的功能,可用于写入要执行二进制输出的数据?

A - Write

B - Output.binary

C - Dump

D - Binary.output

Answer : C

问9 - 假设您正在使用网格管理器,那么哪个选项最适合将组件放在多个行和列中?

A - Columnspan和rowspan

B - Only row

C - 仅列

D - Only rowspan

Answer : A

↑回到顶部↑
WIKI教程 @2018