PythonPython30个笔试题

Posted Better Bench

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PythonPython30个笔试题相关的知识,希望对你有一定的参考价值。

Python测试题

1.求结果:( )

v = dict.fromkeys([‘k1’,‘k2’],[])
v[‘k1’].append(666)
print(v)
v[‘k1’] = 777
print(v)

A.“K1”:[666],“K2”:[666] “K1”:777,“K2”:666
B.“K1”:[666],“K2”:666 “K1”:777,“K2”:[666]
C.“K1”:666,“K2”:[666] “K1”:777,“K2”:[666]
D.“K1”:[666],“K2”:[666] “K1”:777,“K2”:[666]
答案: D

2.一下不是常见的内置函数?( )
A.map B.reduce C.filter D.mapreduce

答案: D

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

4.df是一个DataFrame,下面用法不正确的是( )
A.df.apply(lambda x:x.sum(), axis=1)
B.df.applymap(abs)
C.df.rolling(10).apply(lambda x:x.rank())
D.df.applymap(np.log)
答案: B
5.下列哪个语句在Python中是非法的?( )

A、x = y = z = 1 B、x = (y = z + 1)

C、x, y = y, x D、x += y
答案: B
6、下列哪种说法是错误的 ( )

A、除字典类型外,所有标准对象均可以用于布尔测试
B、空字符串的布尔值是False

C、空列表对象的布尔值是False

D、值为0的任何数字对象的布尔值是False
答案: D

7、下列Python语句正确的是 ()

A、min = x if x < y else y

B、max = x > y ? x : y

C、if (x > y) print x

D、while True : pass
答案: D

8、函数如下:

def showNnumber(numbers):
for n in numbers:
print(n)

下面那些在调用函数时会报错( )

A showNumer([2,4,5]) B showNnumber(‘abcesf’)

C showNnumber(3.4) D showNumber((12,4,5))
答案: C

9、 函数如下

def chanageInt(number2):
number2 = number2+1
print("changeInt: number2= ",number2)
#调用
number1 = 2
chanageInt(number1)
print(“number:”,number1)

打印结果哪项是正确的( )

A changeInt: number2= 3
number: 3
B changeInt: number2= 3
number: 2
C number: 2
changeInt: number2= 2
D number: 2
changeInt: number2= 3

答案: B

10、class A:
Pass
可实现类A可迭代的函数是( )

A._new_
B._iter_
C._dict_
D._iterator_

答案: B
11、定义类如下:

   class hello():
 	def showInfo(self):
  	print(self.x)

下面描述正确的是( )

A该类不可以实例化

B 该类可以实例化

C 在pycharm 工具中会出现语法错误,说self有定义

D 该类可以实例化,并且能正常通过对象调用showInfo()

答案: AC

12、定义类如下

 class Hello():
	def __init__(self,name)
		self.name=name
	def showInfo(self)
		print(self.name)

下面代码能正常执行的 ( )

A h = Hello

h.showInfo()

B h = Hello()

h.showInfo(‘张三’)

C h = Hello(‘张三’)

h.showInfo()

D h = Hello(‘admin’)

showInfo
答案: C
13、

g = (xx for x in range(10)),L = [xx for x in range(10)]

正确的是( )
A.g==L
B.g[0]==L[0]
C.Type(g)==type(L)
D.Sum(g)==sum(L)
答案: D

14 下面定义函数正确的是:( )
A.def func(a,*args,b):pass
B.Def func(a,**kwargs):pass
C.Def func(a,**kwargs, *args, c):pass
D.Def func(a,b,*args, **kwargs):pass

答案: D

15、

a = [1,2,3,4,5,6,7]
b = filter(lambda x: x > 5, a)
print b

下面正确的是:( )
A.[6,7]
B.[7,6]
C.[5,7,6]
D.[5,6,7]
答案: A
16.reduce(lambda x,y:x*y,range(1,4))
下面正确的是( )

A.6
B.7
C.8
D.9
答案: A
17、

import copy
a = [1, 2, 3, 4, [‘a’, ‘b’]] #原始对象
b = copy.copy(a)
c = copy.deepcopy(a)

正确的是( )
A.id(a[1])!=id(b[1])
B.id(a[-1])==id(b[-1])
C.id(a[-1])==id(c[-1])
D.id(a[0])!=id(b[0])!=id(c[0])

答案: B
18. 导入模块的方式错误的是( )

A import mo B from mo import *

C import mo as m D import m from mo
答案: D
19、
A1 = ‘小明’:93,‘小红’:88,‘小刚’:100
A2 = ‘小刚’:100,‘小明’:93,‘小红’:88
print(A1 == A2)

下面正确的是:( )

A、A1 == A2
B、False
C、”False”
D、True
答案: D

20、

a = [1,2,3]
b = [4,5]
A.append(b)

下面正确的是( )
A.Len(a)==4
B.Len(a)==5
C.sum(a)==15
D.a[-1]==5
答案: A
21、

a = “601988-中国银行”
print(re.findall(“(\\d+)-([\\u4e00-\\u9fa5]+)”, a))

下面正确的是( )
A.[(‘601988’, ‘中国银行’)]
B.“‘601988’”
C.“中国银行”
D.(‘601988’, ‘中国银行’)
答案: A
22、

a = “a”:1, “b”:2, “c”:3
print(Max(a))
print(max(a), key=lambda x:a[x])

下面正确的是( )
A.”c” 和3
B.“c”和”c”
C.“3”和”3”
D.“3”和”c”
答案: C
23、

a = [(“a”, 3), (“b”, 2), (“d”, 0)]
sorted(a, key= lambda x:a[0])

下面正确的是( )
A.[(“a”, 3), (“b”, 2), (“d”, 0)]
B.[(“d”, 0), (“”b, 2), (“a”,3)]
C.[(“a”, 0), (“b”, 2), (“d”,3)]
D.[(“a”, 3), (“b”, 2), (“d”,0)]
答案: A

24、df是一个DataFrame,,均值填充NaN值( )
A.df.fillna(df.mean())
B.Df.fillna(method=”ffill”)
C.df.fillna(“mean”)
D.Df.fillna(np.mean)
答案: A

25、下面不能提高python性能的是( )
A.Map
B.Numpy
C.For
D.Cython
答案: C
26、

from collections import defaultdict, OrderedDict

a = defaultdict(OrderedDict)
def func(code, i):
    a[code][i] = i
def timer():
    while 300000!=sum(map(lambda code: len(a[code]), a.keys())):
        print(sum(map(lambda code: len(a[code]), a.keys())))
        time.sleep(1)
    print("ending")
t0 = Thread(target=timer)
t0.start()

ts = []
for code in ["a", "b", "c"]:
    for i in range(100000):
        t = Thread(target=func, args=(code, i, ))
        ts.append(t)
        t.start()

for t in ts:
t.join()

print(sum([set(a[k].keys())!=set(a[k].values()) for k in a]))

下面正确的是( )
A.0
B.100000
C.99999
D.4999950000
答案: ?
27.print(0 or False and 1)
下面正确的是( )
A.False
B.0
C.1
D.True
答案: A
28、

from collections import deque

queue = deque(['Eric', 'John', 'Michael'])
queue.append('Terry')
queue.append('Graham')
print(queue)
queue.popleft()
print(queue)

下面正确的是( )
A.deque([‘Eric’, ‘John’, ‘Michael’, ‘Terry’, ‘Graham’])
deque([‘John’, ‘Michael’, ‘Terry’, ‘Graham’])
B.[‘Eric’, ‘John’, ‘Michael’, ‘Terry’, ‘Graham’]
[‘John’, ‘Michael’, ‘Terry’, ‘Graham’]
C.deque([‘Eric’, ‘John’, ‘Michael’, ‘Terry’, ‘Graham’])
[‘John’, ‘Michael’, ‘Terry’, ‘Graham’]
D.[‘Eric’, ‘John’, ‘Michael’, ‘Terry’, ‘Graham’]
deque([‘John’, ‘Michael’, ‘Terry’, ‘Graham’])
答案: A

29、
df1, df2都是DataFrame
df1,df2=df1.align(df2, join=‘inner’)
下面正确的是( )

A.df1.columnsdf2.columns and df1.indexdf2.index
B.df1.columns!=df2.columns and df1.index!=df2.index
C.df1.columns!=df2.columns and df1.indexdf2.index
D.df1.columns
df2.columns and df1.index!=df2.index
答案: A
30、

def mul(x):
    return x*x
n=[1,2,3,4,5]
res=list(map(mul,n))
print(res)

下面正确的是( )
A.[1, 4, 9, 16, 25]
B.[1,2,3,4,5]
C.<map at 0x25d57825400>]
D.[1,4,3,4,25]

答案: A

以上是关于PythonPython30个笔试题的主要内容,如果未能解决你的问题,请参考以下文章

机器学习机器学习30个笔试题

机器学习机器学习30个笔试题

前端几个笔试题及答案(bd)

机器学习深度学习20个笔试题

机器学习深度学习20个笔试题

关于面试总结4-python笔试题