Python程序设计试题库(共43页).docx
精选优质文档-倾情为你奉上Python程序设计题库一、 填空题第一章 基础知识1、 Python安装扩展库常用的是_工具。(pip)2、 Python标准库math中用来计算平方根的函数是_。(sqrt)3、 Python程序文件扩展名主要有_和_两种,其中后者常用于GUI程序。(py、pyw)4、 Python源代码程序编译后的文件扩展名为_。(pyc)5、 使用pip工具升级科学计算扩展库numpy的完整命令是_。(pip install -upgrade numpy)6、 使用pip工具查看当前已安装的Python扩展库的完整命令是_。(pip list)7、 在IDLE交互模式中浏览上一条语句的快捷键是_。(Alt+P)8、 在Python中_表示空类型。(None)9、 列表、元组、字符串是Python的_(有序无序)序列。(有序)10、 查看变量类型的Python内置函数是_。(type())11、 查看变量内存地址的Python内置函数是_。(id())12、 以3为实部4为虚部,Python复数的表达形式为_或_。(3+4j、3+4J)13、 Python运算符中用来计算整商的是_。(ount(4) 的值为_。(0)14、 Python标准库random中的_方法作用是从序列中随机选择1个元素。(choice())15、 Python标准库random中的sample(seq, k)方法作用是从序列中选择_(重复不重复)的k个元素。(不重复)16、 random模块中_方法的作用是将列表中的元素随机乱序。(shuffle())17、 执行代码 x, y, z = sorted(1, 3, 2) 之后,变量y的值为_。(2)18、 表达式 (1, 2, 3)+(4, 5) 的值为_。((1, 2, 3, 4, 5))19、 表达式 dict(zip(1, 2, 3, 4) 的值为_。(1: 3, 2: 4)20、 语句 x, y, z = 1, 2, 3 执行后,变量y的值为_。(2)21、 已知 x = 1,3,3, 2,3,1,那么表达式 sorted(x, key=lambda item:item0+item2) 的值为_。(2, 3, 1, 1, 3, 3)22、 已知 x = 1,3,3, 2,3,1,那么表达式 sorted(x, key=lambda item:(item1,item2) 的值为_。(2, 3, 1, 1, 3, 3)23、 已知 x = 1,3,3, 2,3,1,那么表达式 sorted(x, key=lambda item:(item1, -item2) 的值为_。(1, 3, 3, 2, 3, 1)24、 已知 x = 1, 2, 3,那么执行语句 (3) 之后,x的值为_。(1, 2, 3)25、 已知 x = 1:1,那么执行语句 x2 = 2之后,len(x)的值为_。(2)26、 已知 x = 1:1, 2:2,那么执行语句 x2 = 4之后,len(x)的值为_。(2)27、 假设已从标准库functools导入reduce()函数,那么表达式 reduce(lambda x, y: x-y, 1, 2, 3) 的值为_。(-4)28、 假设已从标准库functools导入reduce()函数,那么表达式 reduce(lambda x, y: x+y, 1, 2, 3) 的值为_。(6)29、 假设已从标准库functools导入reduce()函数,那么表达式reduce(lambda x,y:max(x,y), 1,2,3,4,4,5)的值为_。(5)30、 已知有函数定义 def demo(*p):return sum(p),那么表达式 demo(1, 2, 3) 的值为_、表达式 demo(1, 2, 3, 4) 的值为_。(6、10)31、 已知列表 x = 1, 2,那么连续执行命令 y = x和 (3) 之后,x的值为_。(1, 2, 3)32、 已知列表 x = 1, 2,那么连续执行命令 y = x: 和 (3) 之后,x的值为_。(1, 2)33、 已知列表 x = 1, 2,执行语句 y = x: 后,表达式 id(x) = id(y) 的值为_。(False)34、 已知列表 x = 1, 2,执行语句 y = x 后,表达式 id(x) = id(y) 的值为_。(True)35、 已知列表 x = 1, 2,执行语句 y = x 后,表达式 x is y 的值为_。(True)36、 已知列表 x = 1, 2,执行语句 y = x: 后,表达式 x is not y 的值为_。(True)37、 表达式 sorted(range(5), 5) 的值为_。(0, 1, 2, 3, 4)38、 表达式 i for i in range(10) if i>8 的值为_。(9)39、 已知有列表 x = 1, 2, 3, 4, 5, 6,那么表达式 rowi for row in x for i in range(len(x0) 的值为_。(1, 4, 2, 5, 3, 6)40、 执行语句 x,y,z = map(str, range(3) 之后,变量y的值为_。('1')41、 已知列表 x = 1, 2,那么执行语句 (3) 之后, x的值为_。(1, 2, 3)42、 已知列表 x = 1, 2,那么执行语句 (3) 之后,x的值为_。(1, 2, 3)43、 表达式 print(0b10101) 的值为_。(21)44、 已知 x = 1, 2, 3, 4, 5,那么执行语句 del x:3 之后,x的值为_。(4, 5)45、 已知 x = range(1,4) 和 y = range(4,7),那么表达式 sum(i*j for i,j in zip(x,y) 的值为_。(32)46、 表达式 5 for i in range(3) 的值为_。(5, 5, 5)47、 表达式 1, 2, 3 = 1, 3, 2 的值为_。(True)48、 表达式 1, 2, 3 = 1, 3, 2 的值为_。(False)49、 已知 x = 1, 2, 1,那么表达式 id(x0) = id(x2) 的值为_。(True)50、 表达式 3 not in 1, 2, 3的值为_。(False)51、 已知 x = 1, 2,那么执行语句 x0:0 = 3, 3之后,x的值为_。(3, 3, 1, 2)52、 已知 x = 1, 2,那么执行语句 x0:1 = 3, 3之后,x的值为_。(3, 3, 2)53、 已知 x = 1, 2, 3, 4, 5,那么执行语句 del x1:3 之后,x的值为_。(1, 4, 5)54、 已知 x = 1, 2, 3, 4, 5, 6,那么表达式 sum(i*j for i,j in zip(*x) 的值为_。(32)55、 已知列表 x = 1, 2, 3 和 y = 4, 5, 6,那么表达式 (i,j) for i, j in zip(x,y) if i=3 的值为_。((3, 6))56、 已知列表 x = , , ,那么表达式 sum(x)/len(x) 的值为_。()57、 已知 x = 1:2, 2:3, 3:4,那么表达式 sum(x) 的值为_。(6)58、 已知 x = 1:2, 2:3, 3:4,那么表达式 sum() 的值为_。(9)59、 已知 x = 3, 2, 3, 3, 4,那么表达式 index for index, value in enumerate(x) if value=3 的值为_。(0, 2, 3)60、 表达式 1234%1000oin(item1 for item in () 的值为_。('345')61、 已知列表 x = 1, 3, 2,那么表达式 value for index, value in enumerate(x) if index=2 的值为_。(2)62、 已知列表 x = 1, 3, 2,那么执行语句 a, b, c = sorted(x) 之后,b的值为_。(2)63、 已知列表 x = 1, 3, 2,那么执行语句 a, b, c = map(str,sorted(x) 之后,c的值为_。('3')64、 表达式 set(1,2,3) = 1, 2, 3 的值为_。(True)65、 表达式 set(1,2, 2,3) = 1, 2, 3 的值为_。(True)66、 表达式 '%c'%65 = str(65) 的值为_。(False)67、 表达式 '%s'%65 = str(65) 的值为_。(True)68、 表达式 chr(ord('b')32) 的值为_。('B')69、 表达式 'abc' in 'abdcefg' 的值为_。(False)70、 已知x为整数变量,那么表达式 int(hex(x), 16) = x 的值为_。(True)71、 已知 x, y = 3, 5,那么执行x, y = y, x 之后,x的值为_。(5)72、 已知 x = 'abcd' 和 y = 'abcde',那么表达式 i=j for i,j in zip(x,y) 的值为_。(True, True, True, True)73、 已知x = list(range(20),那么表达式x-1的值为_。(19)74、 已知x = 3+4j和y = 5+6j,那么表达式x+y的值为_。(8+10j)75、 已知x = 3,那么执行x += 5之后x的值为_。(3, 5)76、 已知x = 3, 3, 4,那么表达式id(x0)=id(x1)的值为_。(True)77、 表达式int('11', 2)的值为_。(3)78、 表达式int('11', 8)的值为_。(9)79、 表达式int(bin(54321), 2)的值为_。(54321)80、 表达式chr(ord('A')+1)的值为_。('B')81、 表达式int(str(34) = 34的值为_。(True)82、 表达式list(str(3, 4) = 3, 4的值为_。(False)83、 表达式1, 2, 3, 4, 5, 6 5, 6, 7, 8的值为_。(1, 2, 3, 4, 7, 8)84、 表达式15 alues()的值为_。(3, 9, 78)85、 已知x = 3, 2, 4, 1,那么执行语句x = ()之后,x的值为_。(None)86、 表达式list(filter(lambda x: x>5, range(10)的值为_。(6, 7, 8, 9)87、 已知x = list(range(20),那么语句print(x100:200)的输出结果为_。()88、 已知x = list(range(20),那么执行语句x:18 = 后列表x的值为_。(18, 19)89、 已知x = 1, 2, 3,那么连续执行y = x:和(4)这两条语句之后,x的值为_。(1, 2, 3)90、 已知x = 1, 2, 3,那么连续执行y = x和(4)这两条语句之后,x的值为_。(1, 2, 3, 4)91、 已知x = 1, 2, 3,那么连续执行y = 1, 2, 3和(4)这两条语句之后,x的值为_。(1, 2, 3)92、 已知x = * 3,那么执行语句x0.append(1)之后,x的值为_。(1, 1, 1)93、 已知x = for i in range(3),那么执行语句x0.append(1)之后,x的值为_。(1, , )94、 已知x = (1, 2),那么执行语句x0.append(3)后x的值为_。((1, 3, 2))95、 已知x = 1:1, 2:2,那么执行语句(2:3, 3:3)之后,表达式sorted()的值为_。((1, 1), (2, 3), (3, 3))96、 已知x = 1:1, 2:2,那么执行语句x3 = 3之后,表达式sorted()的值为_。((1, 1), (2, 2), (3, 3))97、 已知x = 1, 2, 3,那么表达式not (set(x*100)-set(x)的值为_。(True)98、 已知x = 1, 2, 3,那么表达式not (set(x*100)&set(x)的值为_。(False)99、 表达式'x': 1, *'y': 2的值为_。('x': 1, 'y': 2)100、 表达式*range(4), 4, *(5, 6, 7)的值为_。(0, 1, 2, 3, 4, 5, 6, 7)101、 已知 x = 1,2,3,4,5,那么执行语句 x:2 = range(3) 之后,x的值为_。(0, 2, 1, 4, 2)102、 已知 x = 1,2,3,4,5,那么执行语句 x:2 = map(lambda y:y!=5,range(3) 之后,x的值为_。(True, 2, True, 4, True)103、 已知 x = 1,2,3,4,5,那么执行语句 x1:2 = sorted(x1:2, reverse=True) 之后,x的值为_。(1, 4, 3, 2, 5)104、 表达式 True*3 的值为_。(3)105、 表达式 False+1 的值为_。(1)第3章 选择结构与循环结构106、 表达式 'ab' in 'acbed' 的值为_。(False)107、 假设n为整数,那么表达式 n&1 = n%2 的值为_。(True)108、 关键字_用于测试一个对象是否是一个可迭代对象的元素。(in)109、 表达式 3<5>2 的值为_。(True)110、 已知 x = 'a':'b', 'c':'d',那么表达式 'a' in x 的值为_。(True)111、 已知 x = 'a':'b', 'c':'d',那么表达式 'b' in x 的值为_。(False)112、 已知 x = 'a':'b', 'c':'d',那么表达式 'b' in () 的值为_。(True)113、 表达式 1<2<3 的值为_。(True)114、 表达式 3 or 5 的值为_。(3)115、 表达式 0 or 5 的值为_。(5)116、 表达式 3 and 5 的值为_。(5)117、 表达式 3 and not 5 的值为_。(False)118、 Python中用于表示逻辑与、逻辑或、逻辑非运算的关键字分别是_、_、_。(and、or、not)119、 Python 语句 for i in range(3):print(i, end=',') 的输出结果为_。(0,1,2,)120、 Python 语句 print(1, 2, 3, sep=',') 的输出结果为_。(1,2,3)121、 对于带有else子句的for循环和while循环,当循环因循环条件不成立而自然结束时_(会不会)执行else中的代码。(会)122、 在循环语句中,_语句的作用是提前结束本层循环。(break)123、 在循环语句中,_语句的作用是提前进入下一次循环。(continue)124、 表达式 5 if 5>6 else (6 if 3>2 else 5) 的值为_。(6)125、 Python关键字elif表示_和_两个单词的缩写。(else、if)126、 表达式 3 in 1, 2, 3 的值为_。(True)127、 表达式 'ac' in 'abce' 的值为_。(False)128、 表达式 not 3 的值为_。(False)第4章 字符串与正则表达式129、 表达式 'abc' in ('abcdefg') 的值为_。(True)130、 表达式 'abc' in 'abcdefg' 的值为_。(False)131、 表达式 'x41' = 'A' 的值为_。(True)132、 Python语句''.join(list('hello world!')执行的结果是_。('hello world!')133、 转义字符rn的含义是_。(回车换行)134、 已知列表对象x = '11', '2', '3',则表达式 max(x) 的值为_。('3')135、 表达式 min('11', '2', '3') 的值为_。('11')136、 已知列表对象x = '11', '2', '3',则表达式max(x, key=len) 的值为_。('11')137、 已知 path = r'c:',那么表达式 path:-4+'htm' 的值为_。('c:')138、 表达式 list(str(1,2,3) = 1,2,3 的值为_。(False)139、 表达式 str(1, 2, 3) 的值为_。('1, 2, 3')140、 表达式 str(1, 2, 3) 的值为_。('(1, 2, 3)')141、 表达式 sum(range(1, 10, 2) 的值为_。(25)142、 表达式 sum(range(1, 10) 的值为_。(45)143、 表达式 '%c'%65 的值为_。('A')144、 表达式 '%s'%65 的值为_。('65')145、 表达式 '%d,%c' % (65, 65) 的值为_。('65,A')146、 表达式 'The first:1, the second is 0'.format(65,97) 的值为_。('The first:97, the second is 65')147、 表达式 '0:#d,0:#x,0:#o'.format(65) 的值为_。('65,0x41,0o101')148、 表达式 isinstance('abcdefg', str) 的值为_。(True)149、 表达式 isinstance('abcdefg', object) 的值为_。(True)150、 表达式 isinstance(3, object) 的值为_。(True)151、 表达式 'abcabcabc'.rindex('abc') 的值为_。(6)152、 表达式 ':'.join('abcdefg'.split('cd') 的值为_。('ab:efg')153、 表达式 'Hello world. I like Python.'.rfind('python') 的值为_。(-1)154、 表达式 'abcabcabc'.count('abc') 的值为_。(3)155、 表达式 ',banana,pear'.find('p') 的值为_。(1)156、 表达式 ',banana,pear'.find('ppp') 的值为_。(-1)157、 表达式 'abcdefg'.split('d') 的值为_。('abc', 'efg')158、 表达式 ':'.join('1,2,3,4,5'.split(',') 的值为_。('1:2:3:4:5')159、 表达式 ','.join('a b cccnnnddd '.split() 的值为_。('a,b,ccc,ddd')160、 表达式 'Hello world'.upper() 的值为_。('HELLO WORLD')161、 表达式 'Hello world'.lower() 的值为_。('hello world')162、 表达式 'Hello world'.lower().upper() 的值为_。('HELLO WORLD')163、 表达式 'Hello world'.swapcase().swapcase() 的值为_。('Hello world')164、 表达式 r'c:windows'.endswith('.exe') 的值为_。(True)165、 表达式 r'c:windows'.endswith('.jpg', '.exe') 的值为_。(True)166、 表达式 'C:Windows'.startswith('C:') 的值为_。(True)167、 表达式 len('Hello world!'.ljust(20) 的值为_。(20)168、 表达式 len('abcdefg'.ljust(3) 的值为_。(7)169、 表达式 'a' + 'b' 的值为_。('ab')170、 已知 x = '123' 和 y = '456',那么表达式 x + y 的值为_。('')171、 表达式 'a'.join('abc'.partition('a') 的值为_。('aaabc')172、 表达式 ('.+', '.gamma.delta') 的值为_。('alpha', 'beta', 'gamma', 'delta')173、 已知 x = 'a234b123c',并且re模块已导入,则表达式 ('d+', x) 的值为_。('a', 'b', 'c')174、 表达式 ''.join('asdssfff'.split('sd') 的值为_。('assfff')175、 表达式 ''.join('sd','asdssfff') 的值为_。('afff')176、 假设re模块已导入,那么表达式 ('(d)1+', '33abcd112') 的值为_。('3', '1')177、 语句 print('abc', 'defg') 输出结果为_。(None)178、 表达式 'Hello world!'-4 的值为_。('r')179、 表达式 'Hello world!'-4: 的值为_。('rld!')180、 表达式 ''.endswith('.py', '.pyw') 的值为_。(True)181、 表达式 len('abc'.ljust(20) 的值为_。(20)182、 代码 print('a-zA-Z+$','abcDEFG000') 的输出结果为_。(None)183、 当在字符串前加上小写字母_或大写字母_表示原始字符串,不对其中的任何字符进行转义。(r、R)184、 在设计正则表达式时,字符_紧随任何其他限定符(*、+、?、n、n,、n,m)之后时,匹配模式是“非贪心的”,匹配搜索到的、尽可能短的字符串。(?)185、 假设正则表达式模块re已导入,那么表达式 ('d+', '1', 'a12345bbbb67c890d0e') 的值为_。('a1bbbb1c1d1e')186、 表达式 len('中国'.encode('utf-8') 的值为_。(6)187、 表达式 len('中国'.encode('gbk') 的值为_。(4)188、 表达式 chr(ord('A')+2) 的值为_。('C')189、 表达式 'abcab'.replace('a','yy') 的值为_。('yybcyyb')190、 已知 table = ''.maketrans('abcw', 'xyzc'),那么表达式 'Hellow world'.translate(table) 的值为_。('Helloc corld')191、 表达式 'hello world, hellow every one'.replace('hello', 'hi') 的值为_。('hi world, hiw every one')192、 已知字符串 x = 'hello world',那么执行语句 ('hello', 'hi') 之后,x的值为_。('hello world')193、 正则表达式元字符_用来表示该符号前面的字符或子模式1次或多次出现。(+)194、 已知 x = 'a b c d',那么表达式 ','.join() 的值为_。('a,b,c,d')195、 正则表达式元字符_用来表示该符号前面的字符或子模式0次或多次出现。(*)196、 表达式 'abcab'.strip('ab') 的值为_。('c')197、 表达式 str(i) for i in range(3) 的值为_。('0', '1', '2')198、 表达式 ''.endswith('.txt', '.doc', '.jpg') 的值为_。(True)199、 代码 print(1,2,3,sep=':') 的执行结果为_。(1:2:3)200、 代码 for i in range(3):print(i, end=',') 的执行结果为_。(0,1,2,)201、 表达式 eval('''_import_('math').sqrt(9)''') 的值为_。()202、 表达式 eval('''_import_('math').sqrt(3*2+4*2)''') 的值为_。()203、 表达式 eval('3+5') 的值为_。(8)204、 表达式 eval('1, 2, 3') 的值为_。(1, 2, 3)205、 假设math标准库已导入,那么表达式 eval('(4)') 的值为_。()206、 已知x为非空列表,那么表达式 (x) in x 的值为_。(True)207、 表达式 'abc10'.isalnum() 的值为_。(True)208、 表达式 'abc10'.isalpha() 的值为_。(False)209、 表达式 'abc10'.isdigit() 的值为_。(False)210、 表达式 'C:windows'.endswith('.exe') 的值为_。(True)211、 表达式 '%s'%1,2,3 的值为_。('1, 2, 3')212、 表达式 'aaasdf'.lstrip('as') 的值为_。('df')213、 表达式 'aaasdf'.lstrip('af') 的值为_。('sdf')214、 表达式 'aaasdf'.strip('af') 的值为_。('sd')215、 表达式 'aaasdf'.rstrip('af') 的值为_。('aaasd')216、 表达式 len('SDIBT') 的值为_。(5)217、 表达式 'Hello world!'.count('l') 的值为_。(3)218、 已知 x = 'abcdefg',则表达式 x3: + x:3 的值为_。('defgabc')219、 字符串编码格式UTF8使用_个字节表示一个汉字。(3)220、 字符串编码格式GBK使用_个字节表示一个汉字。(2)221、 已知字符串编码格式utf8使用3个字节表示一个汉字、1个字节表示英语字