PYTHON测试题经典.doc
Python经典题库及答案

Python经典题库及答案一、简答题1、写出python导入模块的关键字((1)import,(2)from * import *)2、写出 Python 运算符&的两种功能?(1)数字位运算;2)集合交集运算。
)3、简单解释Python基于值的自动内存管理方式?(Python采用的是基于值得内存管理方式,在Python中可以为不同变量赋值为相同值,这个值在内存中只有一份,多个变量指向同一个内存地址;Python具有自动内存管理功能,会自动跟踪内存中所有的值,对于没有任何变量指向的值,Python 自动将其删除。
)4、在 Python 中导入模块中的对象有哪几种方式?(1)import 模块名 [as 别名];2)from 模块名import 对象名[ as 别名];3)from math import *)5、解释 Python 脚本程序的“ name ”变量及其作用?(每个 Python 脚本在运行时都有一个“ name ”属性。
如果脚本作为模块被导入,则其“ name ”属性的值被自动设置为模块名;如果脚本独立运行,则其“ name ”属性值被自动设置为“main ”。
利用“name ”属性即可控制Python程序的运行方式。
)6、为什么应尽量从列表的尾部进行元素的增加与删除操作?(当列表增加或删除元素时,列表对象自动进行内存扩展或收缩,从而保证元素之间没有缝隙,但这涉及到列表元素的移动,效率较低,应尽量从列表尾部进行元素的增加与删除操作以提高处理速度。
)7、分析逻辑运算符“or”的短路求值特性?(假设有表达式“表达式 1 or 表达式 2”,如果表达式1 的值等价于 True,那么无论表达式 2 的值是什么,整个表达式的值总是等价于 True。
因此,不需要再计算表达式2 的值。
)8、简单解释Python中短字符串驻留机制?(对于短字符串,将其赋值给多个不同的对象时,内存中只有一个副本,多个对象共享改副本。
python基础能力测试习题(带答案详解)

Python 能力测试题一、选择题1.运行下列程序后,输入了一个数字“100”,并按下Enter 键。
下列说法正确的是( ) 1.a = input("请输入任意内容:") 2.if a == '100':3. print ("你输入的是",a)A 、程序不能运行,出现错误提示信息B 、程序能够运行,没有任何错误信息C 、程序不能运行,出现乱码信息D 、程序能够运行,输出“你输入的是:100”2.下述while 循环体执行的次为( )1.k = 100 2.while k > 1: 3.k= k // 3 A 、6 B 、5 C 、4 D 、33.运行下列程序后,程序输出的结果是( ) 1.sum = 0 2.n = 3 3.for i in range(2, 4): 4.n *= 2 5.sum += n 6.print (sum) A 、9 B 、18 C 、21 D 、364.初始时列表L=[10,13,15,12,14,11],列表中的元素经过一系列位置交换后,最大的元素移动到了列表尾部,位置交换后L=[10,13,12,14,11,15],下述能实现这个功能的代码是( )。
5 5、若元组 y=(‘A ’,‘B ’, ‘C ’, ‘D ’),则能够返回元素‘D ’的语句是( )。
A 、y[0]B 、y[3]C 、y[-2]D 、y[4]6、以下程序的最终打印结果( )。
l = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,9 ]print ( l [1 : 4] )A 、[1,2,3]B 、[1,2,3,4]C 、[2,3,4]D 、[2,3]A 、for i in range(6):if L[i] < L[i -1]:L[i],L[i -1] = L[i -1],L[i]B 、for i in range(5): if L[i] < L[i -1]: L[i],L[i -1] = L[i -1],L[i]C 、for i in range(6):if L[i] > L[i+1]:L[i],L[i+1] = L[i+1],L[i] D 、for i in range(5): if L[i] > L[i -1]: L[i],L[i+1] = L[i+1],L[i]7、初始时x = 3,x // 2+x**2 运算后的值为()A、7.5B、10C、8D、10.58、下面程序的作用是()。
Python数据分析测试题(含答案)

自测试卷1一、选择题1.下面关于数据分析说法正确的是()。
A.数据分析是数学、统计学理论结合科学的统计分析方法B.数据分析是一种数学分析方法C.数据分析是统计学分析方法D.数据分析是大数据分析方法2.下面不是数据分析方法的是()。
A.同比分析B.环比分析C.大数据D.帕累托法则3. 下面哪个是同比分析公式()。
A.同比增长速度=(本期-同期)/同期×100%B.同比增长速度=(上期-下期)/上期×100%C.同比增长速度=上期-下期D.同比增长速度=本期-下期4.下面哪个是环比分析公式()。
A.环比增长速度=(本期-下期)/下期×100%B.环比增长速度=本期-上期C.环比增长速度=(本期-上期)/上期×100%D.环比增长速度=(本期-上期)/上期5.关于80/20分析说法不正确的是()。
A.二八法则B.帕累托法则C.帕累托定律D.不规则定律6.类比到头条的收益,头条投放广告预测收益,你选择用哪种方法预测()A.聚类B.一元线性回归C.时间序列D.多元线性回归7.分析客户价值一般使用哪种分析方法?()A.聚类B.一元线性回归C.时间序列D.多元线性回归8.分析股票你选择用哪种分析方法()A.聚类B.一元线性回归C.时间序列D.多元线性回归9.在现实世界的数据中,缺失值是常有的,一般的处理方法有(多选):A.忽略B.删除C.平均值填充D.最大值填充10.Pandas模块用于做什么?(多选)()A.数据挖掘B.数据处理C.数据分析D.数据可视化二、填空题1.数据分析方法一般分为_________、__________、__________。
2.聚类分析多用于_________、__________。
3.数据分析的一般流程是_________、__________、_________、___________、__________、__________、__________。
Python测试题-python测试题

Python测试题一、填空题1.Python使用符号# 标示注释;以缩进对齐划分语句块。
2、Python序列类型包括字符串、列表、元组三种;字典是Python中唯一的映射类型。
3、Python中的可变数据类型有列表和字典,不可变数据类型有字符串、数字、元组。
4、Python的数字类型分为整数、长整数、浮点、复数等子类型。
5、Python提供了两个对象身份比较操作符is 和is not 来测试两个变量是否指向同一个对象,也可以通过内建函数type() 来测试对象的类型。
6、设s=‘abcdefg’,则s[3]值是‘d’,s[3:5]值是‘de’,s[:5]值是‘abcdf’,s[3:]值是‘defg’,s[ : :2]值是‘aceg’,s[::-1]值是‘gfedcba’,s[-2:-5]值是‘’。
二、选择题1.下列哪个语句在Python中是非法的?()A、x = y = z = 1B、x = (y = z + 1)C、x, y = y, xD、x += y2.关于Python内存管理,下列说法错误的是()A、变量不必事先声明B、变量无须先创建和赋值而直接使用C、变量无须指定类型D、可以使用del释放资源3、下面哪个不是Python合法的标识符()A、int32B、40XLC、selfD、__name__4、下列哪种说法是错误的()A、除字典类型外,所有标准对象均可以用于布尔测试B、空字符串的布尔值是FalseC、空列表对象的布尔值是FalseD、值为0的任何数字对象的布尔值是False5、下列表达式的值为True的是()A、5+4j > 2-3jB、3>2>2C、(3,2)< (‘a’,’b’)D、’abc’ > ‘xyz’6、Python不支持的数据类型有()A、charB、intC、floatD、list7、关于Python中的复数,下列说法错误的是()A、表示复数的语法是real + image jB、实部和虚部都是浮点数C、虚部必须后缀j,且必须是小写D、方法conjugate返回复数的共轭复数8、关于字符串下列说法错误的是()A、字符应该视为长度为1的字符串B、字符串以\0标志字符串的结束C、既可以用单引号,也可以用双引号创建字符串D、在三引号字符串中可以包含换行回车等特殊字符9、以下不能创建一个字典的语句是()A、dict1 = {}B、dict2 = { 3 : 5 }C、dict3 = {[1,2,3]: “uestc”}D、dict4 = {(1,2,3): “uestc”}10、下列Python语句正确的是()A、min = x if x < y else yB、max = x > y ? x : yC、if (x > y) print xD、while True : pass三、编程题.1、Python如何定义一个函数,并试写一个函数,给定n,返回n以内的斐波那契数列。
python简答题及答案

python简答题及答案python测试题及答案,python简答题及答案一、选择题(每题2分,共20分)1.下面哪个语句在Python中是非法的?(二)a、x=y=z=1 B、x=(y=z 1)c、x、y=y,x D、x=y?x=x y2.关于Python内存管理,下列说法错误的是(B)a、变量不用提前声明B、变量不用先创建赋值直接使用。
c,变量不需要指定类型D,可以用del释放资源3.3 .打印100-25 * 3% 4输出应该是什么?(二)A.1B.97C.25D.04.以下哪一项不是Python (B)的合法标识符a、int32 B、40XL C、self D 、__name__5.下列哪个陈述是错误的(A)除了字典类型,所有标准对象都可以用于布尔测试。
b,空字符串的布尔值为假c,空列表对象的布尔值为假D.任何数值为0的数字对象的布尔值都是假的。
6.下列表达式中正确的值是(C)5 4j 2-3j B、3221==1和2!=1?d、not(1==1和0!=1)7.Python不支持的数据类型有(A)a、char B、int C、float D、list8.下列不能创建词典的说法是(C)a、字典1={} B、字典2={ 3 : 5 }c、dict3=dict([2,5],[ 3,4 ])d、dict4=dict(([1,2],[3,4])9.下列不能创建集合的说法是(C)a、s1=set () B、s2=set ("abcd ")c、s3=(1,2,3,4) D、s4=frozenset((3,2,1))10.下列Python语句是正确的(D)a、min=x if x y else y B、max=x y and?x : yc、if (x y) print x D、while True :通过二填空(每空一分,共10分)设l=[a , b , c , d , e , f , g],则L[3]的值为_ d _ _?l [:5]的值是_ [d , e] _ l [33605]是_ [a ,b , c , d , e] _ l [:]是_ [在Python中,可变数据类型是_ _ list _ _和_ _ dict _ _,不可变数据类型是_ _ int _ _和_ _ str _ _三、简答题(每题5分,共45分)1声明变量有什么注意事项?答:1.由字母、数字、下划线组成,不能以数字开头;2.不能用关键词。
2024年6月青少年软件编程Python等级考试试卷三级真题(含答案)

2024年6月青少年软件编程Python等级考试试卷三级真题(含答案)分数:100 题数:38一、单选题(共25题,共50分)。
1.现有一组初始记录无序的数据“5,8,6,3,9,2”,使用Python冒泡排序算法,按从小到大的顺序排列,第一轮排序的结果为()。
标准答案:B。
2.题Python列表l=[9,2,8,6,3,4],采用选择排序进行升序排序,第二轮排序后的结果是()。
标准答案:D。
3.经典的韩信点兵问题出自《孙子算经》,译文为,有一些不清楚数量的物品,如果三个为一组的数剩下两个,如果五个为一组的数剩下三个,如果七个为一组的数剩下两个,问这些物品共有多少个。
解决此问题可以用哪种算法()。
A. 解析算法B. 枚举算法C. 排序算法D. 查找算法标准答案:B。
4.下面程序,说法正确的是()。
标准答案:D。
5.题Python的异常处理try...except...else...finally机制中,以下表述哪项是错误的()。
A. 当碰到错误语句时,try代码块的剩余代码将会被忽略,执行except语句块。
B. 当try语句块正确时,try代码块执行完毕,不执行else语句块,执行finally 语句。
C. 不管try代码块正确与否,finally代码都要执行。
D. 项except程序段中语句可能会被执行,也可能不会被执行。
标准答案:B。
6.十进制数25,转化为二进制数为()。
A. 10011B. 11001C. 11000D. 11011标准答案:B。
7.八进制数30,转化为十进制数为()。
A. 24B. 30C. 64D. 192标准答案:A。
8.十进制数90,转化为十六进制数为()。
标准答案:D。
9.下面转化结果与十六进制数3C不相等的是()。
标准答案:C。
10.用python存储某餐馆菜单信息如下:关于该段程序,下列说法正确的是()。
A. 项menu和price组成了一个二维数组。
B. 该段程序一共输出4行结果。
Python经典题库及答案

Python经典题库及答案Python经典题库及答案⼀、简答题1、写出python导⼊模块的关键字((1)import,(2)from * import *)2、写出Python 运算符&的两种功能?(1)数字位运算;2)集合交集运算。
)3、简单解释Python基于值的⾃动内存管理⽅式?(Python采⽤的是基于值得内存管理⽅式,在Python中可以为不同变量赋值为相同值,这个值在内存中只有⼀份,多个变量指向同⼀个内存地址;Python具有⾃动内存管理功能,会⾃动跟踪内存中所有的值,对于没有任何变量指向的值,Python⾃动将其删除。
)4、在Python 中导⼊模块中的对象有哪⼏种⽅式?(1)import 模块名[as 别名];2)from 模块名 import 对象名[ as 别名];3)from math import *)5、解释 Python 脚本程序的“ name ”变量及其作⽤?(每个 Python 脚本在运⾏时都有⼀个“ name ”属性。
如果脚本作为模块被导⼊,则其“ name ”属性的值被⾃动设置为模块名;如果脚本独⽴运⾏,则其“name ”属性值被⾃动设置为“main”。
利⽤“name”属性即可控制Python程序的运⾏⽅式。
)6、为什么应尽量从列表的尾部进⾏元素的增加与删除操作?(当列表增加或删除元素时,列表对象⾃动进⾏内存扩展或收缩,从⽽保证元素之间没有缝隙,但这涉及到列表元素的移动,效率较低,应尽量从列表尾部进⾏元素的增加与删除操作以提⾼处理速度。
)7、分析逻辑运算符“or”的短路求值特性?(假设有表达式“表达式 1 or 表达式 2”,如果表达式 1 的值等价于 True,那么⽆论表达式 2 的值是什么,整个表达式的值总是等价于True。
因此,不需要再计算表达式2的值。
)8、简单解释Python中短字符串驻留机制?(对于短字符串,将其赋值给多个不同的对象时,内存中只有⼀个副本,多个对象共享改副本。
(完整版)Python测试题

Python测试题一、填空题1.Python使用符号# 标示注释;以缩进对齐划分语句块。
2、Python序列类型包括字符串、列表、元组三种;字典是Python中唯一的映射类型。
3、Python中的可变数据类型有列表和字典,不可变数据类型有字符串、数字、元组。
4、Python的数字类型分为整数、长整数、浮点、复数等子类型。
5、Python提供了两个对象身份比较操作符is 和is not 来测试两个变量是否指向同一个对象,也可以通过内建函数type() 来测试对象的类型。
6、设s=‘abcdefg’,则s[3]值是‘d’,s[3:5]值是‘de’,s[:5]值是‘abcdf’,s[3:]值是‘defg’,s[ : :2]值是‘aceg’,s[::-1]值是‘gfedcba’,s[-2:-5]值是‘’。
二、选择题1.下列哪个语句在Python中是非法的?()A、x = y = z = 1B、x = (y = z + 1)C、x, y = y, xD、x += y2.关于Python内存管理,下列说法错误的是()A、变量不必事先声明B、变量无须先创建和赋值而直接使用C、变量无须指定类型D、可以使用del释放资源3、下面哪个不是Python合法的标识符()A、int32B、40XLC、selfD、__name__4、下列哪种说法是错误的()A、除字典类型外,所有标准对象均可以用于布尔测试B、空字符串的布尔值是FalseC、空列表对象的布尔值是FalseD、值为0的任何数字对象的布尔值是False5、下列表达式的值为True的是()A、5+4j > 2-3jB、3>2>2C、(3,2)< (‘a’,’b’)D、’abc’ > ‘xyz’6、Python不支持的数据类型有()A、charB、intC、floatD、list7、关于Python中的复数,下列说法错误的是()A、表示复数的语法是real + image jB、实部和虚部都是浮点数C、虚部必须后缀j,且必须是小写D、方法conjugate返回复数的共轭复数8、关于字符串下列说法错误的是()A、字符应该视为长度为1的字符串B、字符串以\0标志字符串的结束C、既可以用单引号,也可以用双引号创建字符串D、在三引号字符串中可以包含换行回车等特殊字符9、以下不能创建一个字典的语句是()A、dict1 = {}B、dict2 = { 3 : 5 }C、dict3 = {[1,2,3]: “uestc”}D、dict4 = {(1,2,3): “uestc”}10、下列Python语句正确的是()A、min = x if x < y else yB、max = x > y ? x : yC、if (x > y) print xD、while True : pass三、编程题.1、Python如何定义一个函数,并试写一个函数,给定n,返回n以内的斐波那契数列。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
A.defines a list and initializes itB.defines a function, which does nothingC.defines a function, which passes its parameters throughD.defines an empty classA.<type 'int'>B.<type 'number'>C.<type 'float'>D.<type 'double'>E.<type 'tuple'>A.<type 'tuple'>B.<type 'int'>C.<type 'set'>D.<type 'complex'>E.<type 'list'>A.<type 'function'>B.<type 'tuple'>C.<type 'NoneType'>D.<type 'str'>E.<type 'type'>A.<type 'complex'>B.<type 'unicode'>C.<type 'int'>D.<type 'float'>E.<type 'dict'>A.<type 'NoneType'>B.<type 'tuple'>C.<type 'type'>D.<type 'function'>E.<type 'bool'>A.syntax errorB.4C.5D.6E.7A.<type 'int'>B.<type 'number'>C.<type 'float'>D.<type 'double'>E.<type 'tuple'>A.7B.12C.24D.36E.48A.2.0B.2.25C.9.0D.20.25E.21A.1B.2C.4D.5E.7A.yesB.noC.fails to compileA.1B.2C.3D.414. If PYTHONPATH is set in the environment, which directories are searched for modules?(D)A.A onlyB.A and DC.A, B, and CD.A, B, and DE.A, B, C, and D15. In python 2.6 or earlier, the code will print error type 1 if accessSecureSystem raises an exception of either AccessError type or SecurityError type(B)A.trueB.false16. The following code will successfully print the days and then the months(B)A.trueB.false17. Assuming python 2.6 what gets printed?(A)A.TrueB.FalseC.None18. What gets printed?(C)A.1B.3C.4D.7E.none of the above19. What gets printed?(C)A.new line then the string: woowB.the text exactly like this: r"\nwoow"C.the text like exactly like this: \nwoowD.the letter r and then newline then the text: woowE.the letter r then the text like this: nwoow20.What gets printed?(B)A.on one line the text: hello worldB.on one line the text: helloworldC.hello on one line and world on the next lineD.syntax error, this python program will not run21.What gets printed?(E)A.\x48\x49!B.4849C.4849!D. 48 49!E.HI!22. What gets printed?(D)A.0xA + 0xaB.0xA 0xaC.14D.20E.0x2023. What gets printed?(E)A.None NoneB.None 11C.11 NoneD.11 11E.Error is generated by program24. What gets printed?(E)erB.billC.passwordD.hillaryE.Nothing. Python syntax error25. What gets printed?(B)A.NoneB.123C.666D.SyntaxError, this program will not run26. What gets printed?(C)A.stB.stoC.toD.torE.Syntax Error27. What gets printed?(D)A.snow stormB.snowXstormC.snow XtormD.ERROR, this code will not run28. Which numbers are printed?(C)A.2, 4, 6B.0, 1, 2, 4, 5, 6C.0, 1, 4, 5D.0, 1, 4, 5, 6, 7, 8, 9E.1, 2, 4, 5, 629. What sequence of numbers is printed?(B)A.1 2 3B.1 2 1 3C.1 2 1 3 1 2 1 3D.1 1 1 1 2 2 3 3E.Syntax Error30. What sequence of numbers is printed?(E)A.2 3 2 4B.4 6 4 8C.1 1.5 1 2D.1 1 1 2E.4 9 4 1631. What numbers get printed(C)A.500 300B.500 500C.600 400D.600 600E.300 50032. What gets printed by the code snippet below?(B)A.5B.5.0C.5.5D.6E.6.033. What gets printed by the code below?(E)A.1B.2C.49D.50E.5134. What gets printed?(E)A.fooB.foo fooC.foo 2D.2E.An exception is thrown35. What gets printed?(E)A.simpleFunctionB.simpleC.funcD.funtionE.cool36. What does the code below do?(C)A.Changes the location that the python executable is run fromB.Changes the current working directoryC.Adds a new directory to seach for python modules that are importedD.Removes all directories for modsE.Changes the location where sub-processes are searched for after they are launched37. What gets printed?(C)A.3B.7C.13D.14E.1538. Which of the following print statements will print all the names in the list on a seperate line(A)A.print "\n".join(names)B.print names.join("\n")C.print names.concatenate("\n")D.print names.append("\n")E.print names.join("%s\n", names)39. True or false? Code indentation must be 4 spaces when creating a code block?(B)A.TrueB.False40. Assuming the filename for the code below is /usr/lib/python/person.pyand the program is run as:python /usr/lib/python/person.pyWhat gets printed?(D)A.PersonB.getAger.lib.python.personD.__main__E.An exception is thrown41. What gets printed(B)A.setB.dictD.tupleE.object42. What gets printed?(C)A.intB.listC.tupleD.dictE.set43. What gets printed?(D)A.0B.1C.2D.3E.444. What gets printed?(D)A.1B.2C.3D.4E.545. What gets printed?(C)A.2B.4C.6D.7E.An exception is thrown46.What gets printed?(E)B.2C.4D.7E.An exception is thrown47. What gets printed?(E)A.8B.12C.24D.30E.3348. What gets printed?(A)A.0B.1C.2D.3E.An exception is thrown49. What gets printed?(B)B.2C.3D.4E.An exception is thrown50. What gets printed?(E)A.AB.rC.AmirD.DaoE.o51. What gets printed?(B)A.11B.12C.21D.22E.3352. What gets printed?(E)A.-1B.0C.4D.EdwardE.An exception is thrown53. What gets printed?(B)A.1B.2C.An exception is thrown54. What gets printed?(C)A.iB.aC.cD.CE.An exception is thrown55. What gets printed?(B)A.4B.5C.8D.12E.An exception is thrown56. Which of the following data structures can be used with the "in" operator to check if an item is in the data structure?(E)A.listB.setC.dictionaryD.None of the aboveE.All of the above57. Wat gets printed?(D)A.2B.4C.5D.8E.An exception is thrown58. What gets printed?(C)A.1B.4C.5D.8E.An exception is thrown59. What gets printed?(E)A.1B.2C.5D.7E.An exception is thrown60. What gets printed?(B)A.1 2B.2 1C.An exception is thrownD.This program has undefined behavior61. What gets printed?(A)A.+++1 some info+++B.+++%s+++C.1D.some info62. What gets printed?(C)A.strB.intC.tupleD.listE.dict63. What gets printed?(E)A.inB.strC.tupleD.listE.dict64. What gets printed?(B)A.1B.3C.6D.10E.An exception is thrown65. How do you create a package so that the following reference will work?(C)A.Declare the myparser package in mytools.pyB.Create an __init__.py in the home dirC.Inside the mytools dir create a __init__.pyD.Create a myparser.py directory inside the mytools directoryE.This can not be done66. What gets printed?(E)A.1B.2C.3D.6E.767. What gets printed?(E)A.2B.4C.6E.An exception is thrown68. What gets printed?(A)A.hiB.hC.Inside the mytools dir create a __init__.py and myparser.pyD.104105E.10469. What gets printed?(A)A.aB.bC.c70. What gets printed?(C)B.3C.4D.6E.An exception is thrown71. What gets printed (with python version 2.X) assuming the user enters the following at the prompt?(D)#: fooA.fB.fooC.#: fooD.An exception is thrown72. What gets printed?(C)A.4B.5C.10D.15E.An exception is thrown73. If the user types '0' at the prompt what gets printed?(B)A.validB.invalidC.An exception is thrown74. What gets printed?(D)A.1B.2C.7D.10E.An exception is thrown75. What gets printed?(C)A.1B.2C.6D.10E.An exception is thrown76. What gets printed(D)A.1B.2C.6D.10E.An exception is thrown77. What gets printed?(C)A.1B.2C.6D.10E.An exception is thrown78. What gets printed?(C)A.1B.2C.6D.10E.An exception is thrown79. What gets printed?(B)A.15B.51C.150D.An exception is thrown80. What gets printed (with python version 3.X) assuming the user enters the following at the prompt?(B)#: fooA.fB.fooC.Not a numberD.An exception is thrown。