测试题目共30题,测试结果python版本3.6.9

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

echo

output

print

console.log

答案:print

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

Python 的语法类似 PHP

Python 可用于 Web 开发

Python 是跨平台的

Python 可用于数据抓取(爬虫)

答案:Python 的语法类似 PHP

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

*

(comment)

//

#

答案:注释 #

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

'''

///

###

(comment)

答案: 多行注释 '''

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

var a = 2

int a = 2

a = 2

variable a = 2

答案: 赋值正确的是 a = 2

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

castToInt(a)

int(a)

integer(a)

castToInteger(a)

答案: int(a) 转换为整型

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

+=

-=

*=

X=

答案: 赋值操作符错的是X=

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

列表(List)

字典(Dictionary)

元组(Tuples)

类(Class)

答案解释:类是用户自定义的类型。

代码 L = [1, 23, "runoob", 1] 输出的数据类型是?

List

Dictionary

Tuple

Array

答案解释:[] 用于定义一个列表 list

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

print(a[:]) => [1,2,3,4]

print(a[0:]) => [2,3,4,5]

print(a[:100]) => [1,2,3,4,5]

print(a[-1:]) => [1,2]

答案: 正确结果是print(a[:100]) => [1,2,3,4,5]

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

int(x [,base])

long(x [,base] )

float(x)str(x)

答案解释:float(x) − 将 x 转换为浮点数。

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

if a >= 22:

if (a >= 22)

if (a => 22)

if a >= 22

答案: if a>=22: 注意后面的 冒号

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

else if

elseif

elif

以上都不是

答案: elif

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

def someFunction():

function someFunction()

def someFunction()

function someFunction():

答案:def someFunction(): 注意后面的冒号

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

for(a = 0; a < 3; a++)

for a in range(3)

for a loop 3:

for a in range(1,3):

答案:for a in range(1,3): 注意后面的冒号

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

while loop a < 10

while a < 10:

while(a < 10)

while loop a < 10:

答案是:while a < 10: 注意后面冒号

假设你有一个变量 "example",如何判断它的类型?

getType(example)

Type(example)

type(example)

example.type:

答案是:type(example) python是严格区分大小写的

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

example.swap('b', 'a')

example.replace('a','b')

example.match('b','a')

example.replace('b','a')

答案是:example.replace('a','b')

演示:

str = 'example'

print(str.replace('a','b')) # exbmple

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

sampleList = {1,2,3,4,5}

sampleList = (1,2,3,4,5)

sampleList = /1,2,3,4,5/

sampleList = [1,2,3,4,5]

答案是:sampleList = [1,2,3,4,5]

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

sampleTuple = (1,2,3,4,5)

sampleTuple = {1,2,3,4,5}

sampleTuple = [1,2,3,4,5]

sampleList = /1,2,3,4,5/

答案是:sampleTuple = (1,2,3,4,5)

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

myExample = {'someItem'=>2, 'otherItem'=>20}

myExample = {'someItem': 2, 'otherItem': 20}

myExample = ('someItem'=>2, 'otherItem'=>20)

myExample = ('someItem': 2, 'otherItem': 20)

答案是: myExample = {'someItem': 2, 'otherItem': 20} 字典是键值对,中间以:分隔

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

答案是 :

def f(): pass

print(type(f()))

以上代码输出结果为?

答案解释:type() 的参数是函数的返回值,该返回值为 None。所以答案是

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

print(len(a))

以上代码输出结果为?

syntax error

4

5

6

7

答案解释:6 都是合法元素。

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

print(example[2])

echo(example[2])

print(example[1])

print(example(2))

答案: print(example[1]) 可迭代元素索引都是从0开始计算的

print('%.2f' % 123.444) 输出结果为?

123.44

12

123.444

44

答案: 123.44(%.2f 表示保留小数点后面2位)

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

定义一个列表,并初始化它。

定义一个函数,但什么都不做。

定义一个函数,并传递参数。

定义一个空的类。

答案: 定义一个函数,但什么都不做。pass 在这里只是当做占位符使用,主要还是因为此时逻辑思路还不清晰,待后续清晰后在编写代码.

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

catch

exception

catch(a)

except

答案: except

try:

print('...')

except Exception as e:

print('...')

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

f = open("test.txt", "read")

f = open("r","test.txt")

f = open("test.txt", "r")

f = open("read","test.txt")

答案: f = open("test.txt", "r")

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

f = open("test.txt","w")

f = open("test.txt","write")

f = open("write","test.txt")

f = open("w","test.txt")

答案: f = open("test.txt","w")

更多推荐

python基础知识选择题-30题Python基础知识点测试题答案