Python 测验
开始
其他相关测试
-
Python 测验 – 操作符
-
Python 测验 – 条件判断与循环
-
Python 测验 – 函数
$(function() {
$(‘#quiz’).quiz({
//resultsScreen: ‘#results-screen’,
//counter: false,
//homeButton: ‘#custom-home’,
counterFormat: ‘第 %current 题,共 %total 题’,
resultsFormat: ‘回答正确 %score 题,总共 %total 题!’,
nextButtonText: ‘下一题’,
finishButtonText: ‘完成’,
restartButtonText: ‘重新测验’,
questions: [
{
‘q’: ‘Python 中,以下哪个函数是用于输出内容到终端的?’,
‘options’: [
‘echo’,
‘output’,
‘print’,
‘console.log’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 print。’
},
{
‘q’: ‘以下关于 Python 的描述错误的是?’,
‘options’: [
‘Python 的语法类似 PHP’,
‘Python 可用于 Web 开发’,
‘Python 是跨平台的’,
‘Python 可用于数据抓取(爬虫)’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,Python 的语法与 PHP 有很大差异。’
},
{
‘q’: ‘以下哪个符号是用作 Python 的注释?’,
‘options’: [
‘*’,
‘(comment)’,
‘//’,
‘#’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 #。’
},
{
‘q’: ‘以下哪个标记是用作 Python 的多行注释?’,
‘options’: [
‘\’\’\”,
‘///’,
‘###’,
‘(comment)’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为\’\’\’。’
},
{
‘q’: ‘Python 中,以下哪个变量的赋值是正确的?’,
‘options’: [
‘var a = 2’,
‘int a = 2’,
‘a = 2’,
‘variable a = 2’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 a = 2。’
},
{
‘q’: ‘变量 a 的值为字符串类型的 “2”,如何将它转换为整型?’,
‘options’: [
‘castToInt(a)’,
‘int(a)’,
‘integer(a)’,
‘castToInteger(a)’
],
‘correctIndex’: 1,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 int(a)。’
},
{
‘q’: ‘Python 中,以下哪个赋值操作符是错误的?’,
‘options’: [
‘+=’,
‘-=’,
‘*=’,
‘X=’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 X=。’
},
{
‘q’: ‘下面哪一个不是 Python 的数据类型?’,
‘options’: [
‘列表(List)’,
‘字典(Dictionary)’,
‘元组(Tuples)’,
‘类(Class)’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确,类是用户自定义的类型。’,
‘incorrectResponse’: ‘回答错误,类是用户自定义的类型。’
},
{
‘q’: ‘代码 L = [1, 23, “runoob”, 1] 输出的数据类型是?’,
‘options’: [
‘List’,
‘Dictionary’,
‘Tuple’,
‘Array’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确,[] 用于定义一个列表。’,
‘incorrectResponse’: ‘回答错误,[] 用于定义一个列表。’
},
{
‘q’: ‘代码 a = [ 1,2,3,4,5 ],以下输出结果正确的是?’,
‘options’: [
‘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]’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确!’,
‘incorrectResponse’: ‘回答错误!’
},
{
‘q’: ‘以下哪个代码是将字符串转换为浮点数?’,
‘options’: [
‘int(x [,base])’,
‘long(x [,base] )’,
‘float(x)’,
‘str(x)’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确,float(x) − 将 x 转换为浮点数。’,
‘incorrectResponse’: ‘回答错误,float(x) − 将 x 转换为浮点数。’
},
{
‘q’: ‘以下哪个 if 语句是正确的?’,
‘options’: [
‘if a >= 22:’,
‘if (a >= 22)’,
‘if (a => 22)’,
‘if a >= 22’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 if a >= 22:。’
},
{
‘q’: ‘以下哪个关键字是用于给 if 语句添加其他条件语句的?’,
‘options’: [
‘else if’,
‘elseif’,
‘elif’,
‘以上都不是’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 elif。’
},
{
‘q’: ‘以下代码中哪个是定义函数的语句是正确的?’,
‘options’: [
‘def someFunction():’,
‘function someFunction()’,
‘def someFunction()’,
‘function someFunction():’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 def someFunction():。’
},
{
‘q’: ‘以下代码中哪个是正确的 for 循环语句是?’,
‘options’: [
‘for(a = 0; a < 3; a++)’,
‘for a in range(3)’,
‘for a loop 3:’,
‘for a in range(1,3):’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 for a in range(1,3):。’
},
{
‘q’: ‘以下代码中哪个是正确的 while 循环语句是?’,
‘options’: [
‘while loop a < 10’,
‘while a < 10:’,
‘while(a < 10)’,
‘while loop a < 10:’
],
‘correctIndex’: 1,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 while a < 10:。’
},
{
‘q’: ‘假设你有一个变量 “example”,如何判断它的类型?’,
‘options’: [
‘getType(example)’,
‘Type(example)’,
‘type(example)’,
‘example.type:’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 type(example)。’
},
{
‘q’: ‘将字符串 “example” 中的字母 a 替换为字母 b,以下代码正确的是?’,
‘options’: [
‘example.swap(\’b\’, \’a\’)’,
‘example.replace(\’a\’,\’b\’)’,
‘example.match(\’b\’,\’a\’)’,
‘example.replace(\’b\’,\’a\’)’
],
‘correctIndex’: 1,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 example.replace(\’a\’,\’b\’)。’
},
{
‘q’: ‘Python 中,以下哪个代码是正确的列表?’,
‘options’: [
‘sampleList = {1,2,3,4,5}’,
‘sampleList = (1,2,3,4,5)’,
‘sampleList = /1,2,3,4,5/’,
‘sampleList = [1,2,3,4,5]’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 sampleList = [1,2,3,4,5]。’
},
{
‘q’: ‘Python 中,以下哪个代码是正确的元组?’,
‘options’: [
‘sampleTuple = (1,2,3,4,5)’,
‘sampleTuple = {1,2,3,4,5}’,
‘sampleTuple = [1,2,3,4,5]’,
‘sampleList = /1,2,3,4,5/’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 sampleTuple = (1,2,3,4,5)。’
},
{
‘q’: ‘Python 中,以下哪个代码是正确的字典?’,
‘options’: [
‘myExample = {\’someItem\’=>2, \’otherItem\’=>20}’,
‘myExample = {\’someItem\’: 2, \’otherItem\’: 20}’,
‘myExample = (\’someItem\’=>2, \’otherItem\’=>20)’,
‘myExample = (\’someItem\’: 2, \’otherItem\’: 20)’
],
‘correctIndex’: 1,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 myExample = {\’someItem\’: 2, \’otherItem\’: 20}。’
},
{
‘q’: ‘代码 print(type([1,2])) 输出结果为:’,
‘options’: [
‘<class \’tuple\’>’,
‘<class \’int\’>’,
‘<class \’set\’>’,
‘<class \’list\’>’,
‘<class \’complex\’>’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确为 list,列表的定义方式为使用中括号、元素使用逗号隔开。’
},
{
‘q’: ‘
def f(): pass
print(type(f()))
以上代码输出结果为?
‘,
‘options’: [
‘<class \’function\’>’,
‘<class \’tuple\’>’,
‘<class \’NoneType\’>’,
‘<class \’str\’>’,
‘<class \’type\’>’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确, type() 的参数是函数的返回值,该返回值为 None。’,
‘incorrectResponse’: ‘回答错误, type() 的参数是函数的返回值,该返回值为 None。’
},
{
‘q’: ‘
a = [1,2,3,None,(),[],]
print(len(a))
以上代码输出结果为?
‘,
‘options’: [
‘syntax error’,
‘4’,
‘5’,
‘6’,
‘7’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,都是合法元素。’
},
{
‘q’: ‘Python 中,如何输出列表中的第二个元素?’,
‘options’: [
‘print(example[2])’,
‘echo(example[2])’,
‘print(example[1])’,
‘print(example(2))’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 print(example[1])。’
},
{
‘q’: ‘print(\’%.2f\’ % 123.444) 输出结果为?’,
‘options’: [
‘123.44’,
’12’,
‘123.444’,
’44’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 123.44。’
},
{
‘q’: ‘代码 def a(b, c, d): pass 含义是?’,
‘options’: [
‘定义一个列表,并初始化它。’,
‘定义一个函数,但什么都不做。’,
‘定义一个函数,并传递参数。’,
‘定义一个空的类。’
],
‘correctIndex’: 1,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,def 用于定义一个函数,pass 语句表示什么都不做。’
},
{
‘q’: ‘以下哪个关键字是与 try 语句一起使用来处理异常的?’,
‘options’: [
‘catch’,
‘exception’,
‘catch(a)’,
‘except’
],
‘correctIndex’: 3,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 except。’
},
{
‘q’: ‘以下哪个代码是正确的读取一个文件?’,
‘options’: [
‘f = open(“test.txt”, “read”)’,
‘f = open(“r”,”test.txt”)’,
‘f = open(“test.txt”, “r”)’,
‘f = open(“read”,”test.txt”)’
],
‘correctIndex’: 2,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 f = open(“test.txt”, “r”)。’
},
{
‘q’: ‘以下哪个代码是正确的打开文件并准备写入?’,
‘options’: [
‘f = open(“test.txt”,”w”)’,
‘f = open(“test.txt”,”write”)’,
‘f = open(“write”,”test.txt”)’,
‘f = open(“w”,”test.txt”)’
],
‘correctIndex’: 0,
‘correctResponse’: ‘回答正确。’,
‘incorrectResponse’: ‘回答错误,正确答案为 f = open(“test.txt”,”w”)。’
},
]
});
})