Python面试题(选择题及其答案)

往期文章》》》》》》
Python知识点整理(完整)

Python知识点整理,图文结合近三万字(史上最全)

Python二级考试知识点(史上最全)

Python二级考试试题汇总(史上最全)

2023年Python选择题及答案解析【35道】

1、下面代码的输出结果是 ( )

a = "alex"
b = a.capitalize()
print(a)
print(b)

A、alex,Alex
B、Alex,Alex
C、alex,ALEX
D、ALEX,alex
正确答案:A

单选题

1、Python 中,以下哪个函数是用于输出内容到终端的?

A、echo
B、output
C、print
D、console、log
正确答案:C

单选题

2、以下关于 Python 的描述错误的是?

A、Python 的语法类似 PHP
B、Python 可用于 Web 开发
C、Python 是跨平台的
D、Python 可用于数据抓取(爬虫)
正确答案:A

2、关于Python以下不能创建一个字典的语句是( )
A、dict1 = {}
B、dict2={3:5}
C、dict3 = {[1,2,3]: “uestc”}
D、dict4 = {(1,2,3): “uestc”}
正确答案:C

单选题

3、以下哪个符号是用作 Python 的注释?

A、*
B、(comment)
C、//
D、#
正确答案:D

单选题

4、以下哪个标记是用作 Python 的多行注释?

A、‘’’
B、///
C、###
D、(comment)
正确答案:A

4、选出非python的关键字()

A、assert
B、finally
C、panic
D、yield
正确答案:C
单选题

5、Python 中,以下哪个变量的赋值是正确的?

A、var a = 2
B、int a = 2
C、a = 2
D、variable a = 2
正确答案:C

单选题

6、变量 a 的值为字符串类型的 “2”,如何将它转换为整型?

A、castToInt(a)
B、int(a)
C、integer(a)
D、castToInteger(a)
正确答案:B

单选题

7、Python 中,以下哪个赋值操作符是错误的?

A、+=
B、-=
C、*=
D、X=
正确答案:D

单选题

8、下面哪一个不是 Python 的数据类型?

A、列表(List)
B、字典(Dictionary)
C、元组(Tuples)
D、类(Class)
正确答案:D

单选题

9、代码 L = [1, 23, “nowcoder”, 1] 输出的数据类型是?

A、List
B、Dictionary
C、Tuple
D、Array
正确答案:A

单选题

10、代码 a = [ 1,2,3,4,5 ],以下输出结果正确的是?

A、print(a[:]) => [1,2,3,4]
B、print(a[0:]) => [2,3,4,5]
C、print(a[:100]) => [1,2,3,4,5]
D、print(a[-1:]) => [1,2]
正确答案:C

单选题

11、以下哪个代码是将字符串转换为浮点数?

A、int(x [,base])
B、long(x [,base])
C、float(x)
D、str(x)
正确答案:C

多选题

12、以下哪个 if 语句是正确的?

A、if a >= 22:
B、if (a >= 22):
C、if (a => 22)
D、if a >= 22
正确答案:AB

单选题

13、以下哪个关键字是用于给 if 语句添加其他条件语句的?

A、else if
B、elseif
C、elif
D、其他都不对
正确答案:C

单选题

14、以下代码中哪个是定义函数的语句是正确的?

A、def someFunction():
B、function someFunction()
C、def someFunction()
D、function someFunction():
正确答案:A

单选题

15、以下代码中哪个是正确的 for 循环语句是?

A、for(a = 0; a < 3; a++)
B、for a in range(3)
C、for a loop 3:
D、for a in range(1,3):
正确答案:D
单选题

16、以下python代码中哪个是正确的 while 循环语句是?

A、while loop a < 10
B、while a <10:
C、while(a < 10)
D、while loop a < 10:
正确答案:B
单选题

17、假设你有一个变量 “example”,如何判断它的类型?

A、getType(example)
B、Type(example)
C、type(example)
D、example、type:
正确答案:C

单选题

18、将字符串 “example” 中的字母 a 替换为字母 b,以下代码正确的是?

A、example、swap(‘b’, ‘a’)
B、example、replace(‘a’,‘b’)
C、example、match(‘b’,‘a’)
D、example、replace(‘b’,‘a’)
正确答案:B

单选题

19、Python 中,以下哪个代码是正确的列表?

A、sampleList = {1,2,3,4,5}
B、sampleList = (1,2,3,4,5)
C、sampleList = /1,2,3,4,5/
D、sampleList = [1,2,3,4,5]
正确答案:D

单选题

20、Python 中,以下哪个代码是正确的元组?

A、sampleTuple = (1,2,3,4,5)
B、sampleTuple = {1,2,3,4,5}
C、sampleTuple = [1,2,3,4,5]
D、sampleList = /1,2,3,4,5/
正确答案:A

单选题

21、Python 中,以下哪个代码是正确的字典?

A、myExample = {‘someItem’=>2, ‘otherItem’=>20}
B、myExample = {‘someItem’: 2, ‘otherItem’: 20}
C、myExample = (‘someItem’=>2, ‘otherItem’=>20)
D、myExample = (‘someItem’: 2, ‘otherItem’: 20)
正确答案:B

单选题

22、代码 print(type([1,2])) 输出结果为:

A、<class ‘tuple’>
B、<class ‘int’>
C、<class ‘set’>
D、<class ‘list’>
E、<class ‘complex’>
正确答案:D

单选题

23、下面代码输出结果为?

def f(): pass
print(type(f()))

A、<class ‘function’>
B、<class ‘tuple’>
C、<class ‘NoneType’>
D、<class ‘str’>
E、<class ‘type’>
正确答案:C
官方解析: type() 的参数是函数的返回值,该返回值为 None。

单选题

24、下面代码输出结果为?

a = [1,2,3,None,(),[],]
print(len(a))

A、syntax error
B、4
C、5
D、6
E、7
正确答案:D

单选题

25、Python 中,如何输出列表中的第二个元素?

A、print(example[2])
B、echo(example[2])
C、print(example[1])
D、print(example(2))
正确答案:C

单选题

26、print(‘%、2f’ % 123、444) 输出结果为?

A、123、44
B、12
C、123、444
D、44
正确答案:A

单选题

27、代码 def a(b, c, d): pass 含义是?

A、定义一个列表,并初始化它。
B、定义一个函数,但什么都不做。
C、定义一个函数,并传递参数。
D、定义一个空的类。
正确答案:B

单选题

28、以下哪个关键字是与 try 语句一起使用来处理异常的?

A、catch
B、exception
C、catch(a)
D、except
正确答案:D

单选题

29、以下哪个代码是正确的读取一个文件?

A、f = open(“test、txt”, “read”)
B、f = open(“r”,“test、txt”)
C、f = open(“test、txt”, “r”)
D、f = open(“read”,“test、txt”)
正确答案:C
单选题

30、以下哪个代码是正确的打开文件并准备写入?

A、f = open(“test、txt”,“w”)
B、f = open(“test、txt”,“write”)
C、f = open(“write”,“test、txt”)
D、f = open(“w”,“test、txt”)
正确答案:A

请添加图片描述

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐