牛客-python题库

1.
 一个段代码定义如下,下列调用结果正确的是?
    def bar(multiple):
    def foo(n):
        return multiple ** n
    return foo


A
bar(2)(3) == 8
B
bar(2)(3) == 6
C
bar(3)(2) == 8
D
bar(3)(2) == 6

2.
下列代码运行结果是?
    a = map(lambda x: x**3, [1, 2, 3])
list(a)

A
[1, 6, 9]
B
[1, 12, 27]
C
[1, 8, 27]
D
(1, 6, 9)

3.
在Python3中,下列关于数学运算结果正确的是:
a = 10
b = 3
print(a // b)
print(a % b)
print(a / b)

A
3,3,3.3333...
B
3,1,3.3333...
C
3.3333...,3.3333...,3
D
3.3333...,1,3.3333...

4.
在Python3中,执行下列程序结果为:
tmp = 'ab' + 'c'*2
print(tmp)

A
'abc'
B
'abcabc'
C
'abcc'
D
'abc2'

5.
Which numbers are printed?()
    for i in range(2):
    print i
for i in range(4,6):
    print i


A
2, 4, 6
B
0, 1, 2, 4, 5, 6
C
0, 1, 4, 5
D
0, 1, 4, 5, 6, 7, 8, 9
E
1, 2, 4, 5, 6

6.
以下哪一个不是Python支持的数据类型
A
char
B
int
C
float
D
list

7.
在Python3环境中,下列程序运行结果为:
trupls = [(1, 2), (2, 3, 4), (4, 5)]
lists = []
for tru in trupls:
    for num in tru:
        lists.append(num)
print(lists)

A
[1, 2, 3, 4, 5]
B
(1, 2, 2, 3, 4, 4, 5)
C
[1, 2, 2, 3, 4, 4, 5]
D
(1, 2, 3, 4, 5)

8.
在python3中,关于元组的计算如下:
one = (1, 2, 3)
one[2] = 4
print(one[2])

A.None
B.报错:元组中的元素值不支持修改
C.4
D.(4)

9.
    for i in range(2):
    print i
for i in range(4,6):
    print i
上面这段代码打印的结果是()
A.2, 4, 6
B.0,1, 2, 4, 5, 6
C.0, 1, 4, 5
D.0,1, 4, 5, 6, 7, 8, 9

10.
当一个嵌套函数在其外部区域引用了一个值时,该嵌套函数就是一个闭包,以下代码输出值为:
    def adder(x):
    def wrapper(y):
        return x + y
    return wrapper
adder5 = adder(5)
print(adder5(adder5(6)))

A、10
B、12
C、14
D、16

11.
下面哪个是Python中不可变的数据结构?
A、set
B、list
C、tuple
D、dict

12.
What gets printed?()

nums = set([1,2,2,3,3,3,4])
print len(nums)


A、1
B、2
C、4
D、5
E、7

13.
下列程序运行结果为:
a=[1, 2, 3, 4, 5]
sums = sum(map(lambda x: x + 3, a[1::3]))
print(sums)

A、10
B、13
C、15
D、17

14.
Python3中,已知列表a = [2,3],则下列程序结果是
1    print(a*2)


A
[4,6]
B
[4,3]
C
[4,6,4,6]
D
[2,3,2,3]

15.
执行下列选项的程序,会抛出异常的是()
A
s1 = 'aabbcc'
s2 = 'abc'
count = s1.count(s2)
if count > 0 :
print('s2是s1的子串')
else:
print('s2不是s1的子串')
B
s1 = 'aabbcc'
s2 = 'abc'
index = s1.index(s2)
if index > -1:
print('s2是s1的子串')
else:
print('s2不是s1的子串')
C
s1 = 'aabbcc'
s2 = 'abc'
find = s1.find(s2)
if find != -1 :
print('s2是s1的子串')
else:
print('s2不是s1的子串')
D
s1 = 'aabbcc'
s2 = 'abc'
if s2 in s1:
print('s2是s1的子串')
else:
print('s2不是s1的子串')

16.
在Python3中,下列continue的用法:
    res = []
for i in 'python':
    if i == 'h':
        continue
    res.append(i)
print(''.join(res))


A
'p','y','t','h','o','n'
B
'p','y','t','o','n'
C
'python'
D
'pyton'

17.
在Python3中,关于字符串的判断正确的是:
    str1 = ''
str2 = ' '
if not str1:
    print(1)
elif not str2:
    print(2)
else:
    print(0)


A、0
B、1
C、2
D、None

18.
假设可以不考虑计算机运行资源(如内存)的限制,以下 python3 代码的预期运行结果是:()

    import math
def sieve(size):
    sieve= [True] * size
    sieve[0] = False
    sieve[1] = False
    for i in range(2, int(math.sqrt(size)) + 1):
        k= i * 2
        while k < size:
           sieve[k] = False
           k += i
    return sum(1 for x in sieve if x)
print(sieve(10000000000))


A
455052510
B
455052511
C
455052512
D
455052513

19.
在python3.x执行下列选项的程序,不会抛出异常的是()
A
b = 1
def fn():
nonlocal b
b = b + 1
print(b)
fn()
B
tup = (('onion','apple'),('tomato','pear'))
for _,fruit in tup:
print(fruit)
C
a = [b for b in range(10) if b % 2 == 0]
print(b)
D
lis = [1,2,'a',[1,2]]
set(lis)

20.
对于以下代码,描述正确的是:
    list = ['1', '2', '3', '4', '5']
print list[10:]


A
导致 IndexError
B
输出['1', '2', '3', '4', '5']
C
编译错误
D
输出[]

21.
有一段python的编码程序如下,请问经过该编码的字符串的解码顺序是( )    urllib.quote(line.decode("gbk").encode("utf-16"))

A
gbk utf16 url解码
B
gbk url解码 utf16
C
url解码 gbk utf16
D
url解码 utf16 gbk

22.
对于以下代码,描述正确的是:
list = ['1', '2', '3', '4', '5']
print list[10:]
A
导致 IndexError
B
输出['1', '2', '3', '4', '5']
C
编译错误
D
输出[]

23.
对列表a = [1,2,3,1,2,4,6]进行去重后,得到列表b,在不考虑列表元素的排列顺序的前提下,下列方法错误的是()
A
b = list(set(a))
B
b = {}
b = list(b.fromkeys(a))
C
a.sort()
b = []
i = 0
while i < len(a):
if a[i] not in b:
b.append(a[i])
else:
i += 1
D
a.sort()
for i in range(len(a)-1):
if a[i] == a[i+1]:
a.remove(a[i])
else:
continue
b = a

24.
执行以下程序,输出结果为()
a = [['1','2'] for i in range(2)]
b = [['1','2']]*2
a[0][1] = '3'
b[0][0] = '4'
print(a,b) 

A
[['1', '3'], ['1', '3']] [['4', '2'], ['4', '2']]
B
[['1', '3'], ['1', '2']] [['4', '2'], ['4', '2']]
C
[['1', '3'], ['1', '2']] [['4', '2'], ['1', '2']]
D
[['1', '3'], ['1', '3']] [['4', '2'], ['1', '2']]

25.
执行下列选项的程序,输出结果为True的是()
A
lis = [1,3,2]
a = id(lis)
lis = sorted(lis)
b = id(lis)
print(a==b)
B
lis = [1,3,2]
a = id(lis)
lis += [4,5]
b = id(lis)
print(a==b)
C
tup = (1,3,2)
a = id(tup)
tup += (4,5)
b = id(tup)
print(a==b)
D
tup = (1,3,2)
a = id(tup)
tup = sorted(tup)
b = id(tup)
print(a==b)

26.
python变量的查找顺序为()
A
局部作用域>外部嵌套作用域>全局作用域>内置模块作用域
B
外部嵌套作用域>局部作用域>全局作用域>内置模块作用域
C
内置模块作用域>局部作用域>外部嵌套作用域>全局作用域
D
内置模块作用域>外部嵌套作用域>局部作用域>全局作用域

27.
【问题】执行以下代码,结果输出为()
num = 1
def fn():
num += 1
return lambda:print(num)
x = fn()
x()
A
报错
B
2
C
None
D
1
多选题
28.
Python调用(   )函数可实现对文件内容的读取
A
read()
B
readline()
C
readlines()
D
readclose()
多选题
29.
若 a = range(100),以下哪些操作是合法的?
A
a[-3]
B
a[2:13]
C
a[::3]
D
a[2-3]
多选题
30.
下列关于python socket操作叙述正确的是(      )
A
使用recvfrom()接收TCP数据
B
使用getsockname()获取连接套接字的远程地址
C
使用connect()初始化TCP服务器连接
D
服务端使用listen()开始TCP监听

31.
如下代码,执行结果为:
1
    def f(x):
    if x == 0:
        return 0
    elif x == 1:
        return 1
    else:
        return (x*f(x-1))
print(f(5))


A
120
B
720
C
24
D
64

32.
在python3中,以下对程序结果描述正确的是:
dicts = {'one': 1, 'two': 2, 'three': 3}
dicts['four'] = 4
dicts['one'] = 6
print(dicts)


A
{'one': 1, 'two': 2, 'three': 3, 'four': 4}
B
{'one': 6, 'two': 2, 'three': 3}
C
{'one': 1, 'two': 2, 'three': (3, 4)}
D
{'one': 6, 'two': 2, 'three': 3, 'four': 4}

33.
在Python3中,程序运行结果为:
a = 100
b = 14
print(divmod(a, b))


A
(7, 0)
B
(7, 2)
C
[7, 2]
D
None

34.
python3中,执行 not 1 and 1的结果为
A
True
B
False
C
0
D
1

35.
下列哪种类型是Python的映射类型?
A
str
B
list
C
tuple
D
dict

36.
Python3中,下列对程序描述正确的是:
lists = [1, 2, 3, 4, 5, 6]
lists.append([7,8,9])
print(lists)


A
[1,2,3,4,5,6]
B
[1,2,3,4,5,6,[7,8,9]]
C
[1,2,3,4,5,6,7,8,9]
D
[7,8,9]

37.
下列程序打印结果为(      )
nl = [1,2,5,3,5]

nl.append(4)
nl.insert(0,7)
nl.sort()
 
print nl


A
[1, 2, 3, 4, 5, 5, 7]
B
[0, 1, 2, 3, 4, 5, 5]
C
[1, 2, 3, 4, 5, 7]
D
[7, 5, 4, 3, 2, 1]

38.
在Python3中,下列正确的是:
lists = [1, 2, 3]
lists.insert(2, [7,8,9])
print(lists)


A
[1,2,3,7,8,9]
B
[1,2,3,[7,8,9]]
C
[1,2,[7,8,9],3]
D
[1,2,7,8,9,3]

39.
下面程序运行结果为:
    for i in range(5):
    i+=1
    print("-------")
    if i==3:
      continue
    print(i)


A
------- 1 ------- 2 ------- ------- 4 ------- 5
B
------- 1 ------- 2
C
------- 1 ------- 2 ------- 3
D
------- 1 ------- 2 ------- 4 ------- 5

40.
在Python3中,有关于break的用法:
    for i in 'python':
    if i == 'h':
        break
    print(i)


A
'p','y','t','h','o','n'
B
'p','y','t'
C
'p','y','t','h'
D
'pyt'

41.
执行下列选项的程序,输出结果与其他三个选项不同的是()

A
a = [['1']*3 for i in range(3)]
print(a)
B
b = [['1']]*3
print(b)
C
c=[]
for i in range(3):
lis = ['1']*3
c.append(lis)
print(c)
D
d = []
lis = ['1']*3
for i in range(3):
d.append(lis)
print(d)

42.
为输出一个字典dic = {‘a’:1,'b':2},下列选项中,做法错误的是()
A
lis1 = ['a','b']
lis2 = [1,2]
dic = dict(zip(lis1,lis2))
print(dic)
B
tup = ('a','b')
lis = [1,2]
dic = {tup:lis}
print(dic)
C
dic = dict(a=1,b=2)
print(dic)
D
lis = ['a','b']
dic = dict.fromkeys(lis)
dic['a'] = 1
dic['b'] = 2
print(dic)

43.
在Python3中,下列程序循环的次数为:
    n = 1000
while n > 1:
    print(n)
    n = n / 2


A、9
B、10
C、11
D、无限循环

44.
下列哪种不是Python元组的定义方式?
A、(1)
B、(1, )
C、(1, 2)
D、(1, 2, (3, 4))

45.
执行以下程序,输出结果为()
a = 0 or 1 and True
print(a)
A、0
B、1
C、False
D、True

46.
在Python3中,关于字符数组的运行结果为:
    names = ["Andrea", "Aaslay", "Steven", "Joa"]
lists = []
for name in names:
    if name.count('a') >= 2:
        lists.append(name)
print(lists)


A
[‘Andrea’, 'Aaslay', 'Joa']
B
[]
C
[‘Andrea’, 'Aaslay']
D
['Aaslay']

47.
在Python3中,下列程序运行结果为:
lists = [1, 2, 3, 4]
tmp = 0
for i,j in enumerate(lists):
    tmp += i * j
print(tmp)


A、20
B、30
C、100
D、None

48.
在python3运行环境下,执行以下选项中的代码,其输出结果不为[2,4,6,8,10]的是()
A
a = [1,2,3,4,5,6,7,8,9,10]
print(a[1::2])
B
a = [1,2,3,4,5,6,7,8,9,10]
lis = []
for i in a:
if i % 2 == 0:
lis.append(i)
print(lis)
C
a = [1,2,3,4,5,6,7,8,9,10]
print(list(filter(lambda x:x % 2 ==0,a)))
D
a = [1,2,3,4,5,6,7,8,9,10]
def is_odd(n):
return n % 2 == 0
print(list(filter(is_odd(),a)))

49.
在Python3中,执行
    print([2] in [1, 2, 3])
的结果为:

A
True
B
False
C
[2]
D
报错

50.
如下程序会打印多少个数:()
    k = 1000
while k > 1:
    print k
    k = k/2

A、1000
B、10
C、11
D、9

51.
以下代码运行结果为:
func = lambda x:x%2
result = filter(func, [1, 2, 3, 4, 5])
print(list(result))
A
[1,3,5]
B
[1,2,1,0,1]
C
[1, 2, 3, 4, 5]
D
[1,2,3]

52.
What gets printed?()
    print r"\nwoow"

A
new line then the string: woow
B
the text exactly like this: r"\nwoow"
C
the text like exactly like this: \nwoow
D
the letter r and then newline then the text: woow
E
the letter r then the text like this: nwoow

53.
在Python3中关于下列字符串程序运行结果为?
str1 = "exam is a example!" 
str2 = "exam" 
print(str1.find(str2, 7))


A、-1
B、14
C、0
D、10

54.
在Python3中。下列程序运行结果说明正确的是:
strs = 'abcd12efg'
print(strs.upper().title())


A
'ABCD12EFG'
B
'Abc12efg'
C
语法错误
D
'Abcd12Efg'

55.
为了以下程序能够正常运行,①处可以填入的语句是()
    class Animal:
 
    def __init__(self,color):
 
        self.__color = color
 
    @property
 
    def color(self):
 
        return self.__color
 
    @①
 
    def color(self,color):
 
        self.__color = color
 
animal = Animal('red')
 
print(animal.color)
 
animal.color = 'white'
 
print(animal.color)

A
property
B
setter
C
color.setter
D
setter.color

56.
在python3中关键字 pass 的使用,则:
    for i in range(5):
    if i == 2:
        pass
    print(i)


A
1,2,3,4,5
B
0,1,2,3,4
C
0,1,3,4
D
0,1,2,3,4,5

57.
在Python3中,下列程序结果为:
1
2    dicts = {'a': 1, 'b': 2, 'c': 3}
print(dicts.pop())

A
{'c': 3}
B、报错
C、3
D、('c': 3)

58.
执行以下程序,输出结果为()
lis = ['apple','lemon','pear','peach']
def fn(x):
return x[::-1]
lis.sort(key=fn,reverse=True)
print(lis)
A
['apple', 'lemon', 'peach','pear']
B
['pear', 'peach', 'lemon', 'apple']
C
['apple','pear', 'lemon', 'peach']
D
['pear', 'lemon', 'peach', 'apple']

59.
执行下列程序,输出结果为()
def fn():
    t = []
    i = 0
    while i < 2:
        t.append(lambda x: print(i*x,end=","))
        i += 1
    return t
for f in fn():
    f(2)
A、4,4,
B、2,2,
C、0,1,
D、0,2,
多选题
60.
Python中函数是对象,下列描述正确的有?
A
函数可以赋值给一个变量
B
函数可以作为元素添加到集合对象中
C
函数可以作为参数值传递给其它函数
D
函数可以当做函数的返回值

61.
以下哪个代码是正确的读取一个文件?
A
f = open("test.txt", "read")
B
f = open("r","test.txt")
C
f = open("test.txt", "r")
D
f = open("read","test.txt")

62.
在Python3中,运行结果为:
    for i in range(10, 1, -2):
    print(i)


A
9,7,5,3,1
B
10,8,6,4,2
C
1,3,5,7,9
D
10,8,6,4,2,1

63.
下列代码输出为:
str1 = "Hello,Python";
str2 = "Python";
print(str1.index(str2));

A、5
B、6
C、7
D、8

64.
执行下面代码,请问输出结果为()
    name = “顺顺”
def f1():
    print(name)
def f2():
    name = “丰丰”
f1()
f1()
f2()

A
顺顺 顺顺
B
丰丰 丰丰
C
顺顺 丰丰
D
丰丰 顺顺

65.
在Python3中,有关字符串的运算结果为:
    strs = 'I like python and java'
one = strs.find('n')
print(one)
two = strs.rfind('n')
print(two)

A
12,12
B
15,15
C
12,15
D
None,None

66.
下面哪个不是合法的Python标识符?
A、int32
B、40XL
C、self
D、name

67.
在Python3中,下列程序结果为:
    dict1 = {'one': 1, 'two': 2, 'three': 3}
dict2 = {'one': 4, 'tmp': 5}
dict1.update(dict2)
print(dict1)


A
{'one': 1, 'two': 2, 'three': 3, 'tmp': 5}
B
{'one': 4, 'two': 2, 'three': 3}
C
{'one': 1, 'two': 2, 'three': 3}
D
{'one': 4, 'two': 2, 'three': 3, 'tmp': 5}

68.
以下代码输出为:
    list1 = {'1':1,'2':2}
list2 = list1
list1['1'] = 5
sum = list1['1'] + list2['1']
print(sum)

A、1
B、2
C、7
D、10

69.
在Python3中,下列程序运行结果为:
    print('\n'.join(['a', 'b', 'c']))

A
'abc'
B
a b c
C
报错
D
None

70.
在Python3中。程序语句结果为:
    strs = 'abbacabb'
print(strs.strip('ab'))


A、'ab'
B、语法错误
C、'c'
D、‘ca’

11.
在python3中,对程序结果说明正确的是:
    dicts = {'one': 1, 'two': 2, 'three': 3}
tmp = dicts.copy()
tmp['one'] = 'abc'
print(dicts)
print(tmp)

A
['one': 1, 'two': 2, 'three': 3],['one': 'abc', 'two': 2, 'three': 3]
B
{'one': 1, 'two': 2, 'three': 3},{'one': 'abc', 'two': 2, 'three': 3}
C
{'one': 'abc', 'two': 2, 'three': 3},{'one': 'abc', 'two': 2, 'three': 3}
D
{'one': 1, 'two': 2, 'three': 3},{'one': 1, 'two': 2, 'three': 3}

12.
以下程序输出为:
    def w1():
   print('正在装饰')
   def inner():
        print('正在验证权限')
  
   return inner()
  
w1()


A
正在装饰 正在验证权限
B
正在装饰
C
正在验证权限
D
运行错误

13.
在Python3中,关于字符串的运算结果为:
    strs = 'abcd'
print(strs.center(10, '*'))


A
'abcd'
B
'*****abcd*****'
C
'***abcd***'
D
' abcd '

14.
在Python3中,下列程序运行结果为:
    dicts = {}
dicts[(1, 2)] = ({3, (4, 5)})
print(dicts)


A
报错
B
{(1, 2): {(4, 5), 3}}
C
{(1, 2): [(4, 5), 3]}
D
{(1, 2): [3, 4, 5]}

15.
已知print_func.py的代码如下:
    print('Hello
World!')
print('__name__
value: ', __name__)
  
def main():
    
print('This message is from main function')
  
if __name__ ==
'__main__':
    
main()

print_module.py的代码如下:
    import print_func
print("Done!")

运行print_module.py程序,结果是:
A
Hello World! __name__ value: print_func Done!
B
Hello World! __name__ value: print_module Done!
C
Hello World! __name__ value: __main__ Done!
D
Hello World! __name__ value: Done!

16.
关于Python内存管理,下列说法错误的是 
A
变量不必事先声明
B
变量无须先创建和赋值而直接使用
C
变量无须指定类型
D
可以使用del释放资源

17.
执行以下程序,输出结果为()
class Base(object):
    count = 0
    def __init__(self):
        pass
b1 = Base()
b2 = Base()
b1.count = b1.count + 1
print(b1.count,end=" ")
print(Base.count,end=" ")
print(b2.count)
A、1 1 1
B、1 0 0
C、1 0 1
D、抛出异常

18.
以下python代码的输出是什么?
    numbers = [1, 2, 3, 4]
numbers.append([5,6,7,8])
print len(numbers)


A、4
B、5
C、8
D、12
E、An exception is thrown

19.
Python函数如下,则输出结果为:
    def chanageList(nums):     
    nums.append('c')     
    print("nums", nums)   
str1 = ['a', 'b'] 
# 调用函数 
chanageList(str1) 
print("str1", str1)

A
nums ['a', 'b', 'c'],str1 ['a', 'b', 'c']
B
nums ['a', 'b', 'c'],str1 ['a', 'b']
C
nums ['a', 'b'],str1 ['a', 'b']
D
nums ['a', 'b'],str1 ['a', 'b','c']

20.
What gets printed?()
    counter = 1 
def doLotsOfStuff(): 
    global counter
    for i in (1, 2, 3): 
        counter += 1 
doLotsOfStuff()
print counter
A、1
B、3
C、4
D、7
E、none of the above

21.
在python3中,程序运行结果为:
    truple = (1, 2, 3)
print(truple*2)

A
(2,4,6)
B
(1, 2, 3, 1, 2, 3)
C
[1, 2, 3, 1, 2, 3]
D
None

22.
下面关于return说法正确的是(      )
A
python函数中必须有return
B
return可以返回多个值
C
return没有返回值时,函数自动返回Null
D
执行到return时,程序将停止函数内return后面的语句

23.
执行以下程序,输出结果为()
def outer():
    def inner():
        print('inner',end=" ")
    print('outer',end = " ")
    return inner
outer()
A
inner outer
B
inner
C
outer
D
outer inner

24.
关于Python中的复数,下列说法错误的是()
A
表示复数的语法是real + image j
B
实部和虚部都是浮点数
C
虚部必须后缀j,且必须小写
D
方法conjugate返回复数的共轭复数

25.
在Python3中,下列程序结果为:
    strs = ' I like python '
one = strs.split(' ')
two = strs.strip()
print(one)
print(two)

A
['', 'I', 'like', 'python', ''],'I like python '
B
['I', 'like', 'python'],'I like python'
C
['', 'I', 'like', 'python', ''],'I like python'
D
['I', 'like', 'python'],'I like python '

26.
在Python3中,程序运行结果为:
    lists = [1, 1, 2, 3, 4, 5, 6]
lists.remove(1)
lists.extend([7,8,9])
print(lists)

A
[2,3,4,5,6]
B
[1,2,3,4,5,6,[7,8,9]]
C
[1,2,3,4,5,6,7,8,9]
D
[2,3,4,5,6,7,8,9]

27.
执行以下程序,结果输出为()
a = [1]
b = 2
c = 1
def fn(lis,obj):
    lis.append(b)
    obj = obj + 1
    return lis,obj
fn(a,c)
print(fn(a,c))
A
([1, 2, 2], 2)
B
([1, 2, 2], 3)
C
([1, 2], 2)
D
([1, 2], 3)

28.
在Python3中,下列说法正确的是:
    sets = {1, 2, 3, 4, 5}
print(sets[2])
程序运行结果为:

A、2
B、3
C、报错
D、{3}

29.
Assuming the filename for the code below is /usr/lib/python/person.py
and the program is run as: python /usr/lib/python/person.py
What gets printed?()
     class Person:
    def __init__(self):
        pass
    def getAge(self):
        print __name__
p = Person()
p.getAge()

A、Person
B、getAge
C、usr.lib.python.person
D、__main__
多选题
30.
对于下列Python代码,描述正确的有:
    foo = [1,2]
foo1 = foo
foo.append(3)

A
foo 值为[1,2]
B
foo 值为[1,2,3]
C
foo1 值为[1,2]
D
foo1 值为[1,2,3]

1.如下程序的运行结果为:
    def func(s, i, j):
    if i < j:
        func(s, i + 1, j - 1)
        s[i],s[j] = s[j], s[i]
         
def main():
    a = [10, 6, 23, -90, 0, 3]
    func(a, 0, len(a)-1)
    for i in range(6):
        print a[i]
        print "\n"
         
         
main()

A
3
0
‐90
23
6
10
B
3
0
‐60
23
6
10
C
6
10
3
0
‐90
23
D
6
10
3
0
-23
23

2.
在Python3中,程序运行结果为:
    tmp = dict.fromkeys(['a', 'b'], 4)
print(tmp)


A
{('a', 'b'): 4}
B
{'a': 4}
C
{'a': 4, 'b': 4}
D
{ 'b': 4}

3.
在Python3的环境中,如下程序是实现找出1-10中奇数,则横线处应填写:
    for i in range(1, 11):       
    if i % 2 == 0:           
           ______        
    print(i)


A
break
B
yield
C
continue
D
flag

4.
在python3中,下列程序运行结果为:
    strs = ['a', 'ab', 'abc', 'abcd']
dicts ={}
for i in range(len(strs)):
    dicts[i] = strs[i]
print(dicts)


A
[0: 'a', 1: 'ab', 2: 'abc', 3: 'abcd']
B
{1: 'a', 2: 'ab', 3: 'abc', 4: 'abcd'}
C
{0: 'a', 1: 'ab', 2: 'abc', 3: 'abcd'}
D
[1: 'a', 2: 'ab', 3: 'abc', 4: 'abcd']

5.
a与b定义如下,下列哪个选项是正确的?
a = '123'
b = '123'
A
a != b
B
a is b
C
a == 123
D
a + b = 246

6.
以下程序输出为:
7    # -*- coding:utf-8 -*-
def test(a, b, *args):
    print(a)
    print(b)
    print(args)
 
test(11, 22, 33, 44, 55, 66, 77, 88, 99)


A
11 22 (33, 44, 55, 66, 77, 88, 99)
B
编译错误
C
运行错误
D
11 22 (11,22,33, 44, 55, 66, 77, 88, 99)

7.
下列代码输出为:
    str = "Hello,Python";
suffix = "Python";
print (str.endswith(suffix,2));

A、True
B、False
C、语法错误
D、P

8.
以下程序输出为:
    info = {'name':'班长', 'id':100, 'sex':'f', 'address':'北京'}
age = info.get('age')
print(age)
age=info.get('age',18)
print(age)

A
None 18
B
None None
C
编译错误
D
运行错误

9.
有如下函数定义,执行结果正确的是?
    def dec(f):
    n = 3
    def wrapper(*args,**kw):
        return f(*args,**kw) * n
    return wrapper
 
@dec
def foo(n):
    return n * 2


A
foo(2) == 12
B
foo(3) == 12
C
foo(2) == 6
D
foo(3) == 6

10.
下列哪个语句在Python中是非法的?
A
x = y = z = 1
B
x = (y = z + 1)
C
x, y = y, x
D
x += y

    res = 0
for i in range(1, 4):
    for j in range(1, 4):
        for k in range(1, 4):
            if i != j and i != k and j != k:
                res += 1
print(res)
在Python3中,三层循环后res的结果为:
A、6
B、12
C、3
D、5

12.
在Python中关于列表的运算结果为:
    lists = [1, 2, 2, 3, 3, 3]
print(lists.count(3))
print(lists.pop())
lists.pop()
print(lists)

A
2,3,[1, 2, 2, 3]
B
3,3,[1, 2, 2, 3]
C
3,3,[1, 2, 2, 3, 3]
D
2,3,[1, 2, 2, 3, 3]

13.
在Python3中,下列程序返回的结果为:
    strs = '123456'
print(strs.find('9'))


A、None
B、-1
C、报错
D、空

14.
    strs = ' I like python '
one = strs.strip()
print(one)
two = strs.rstrip()
print(two)
在Python3中,关于 strip() 和 rstrip() 的程序运行结果为:
A
'I like python', 'I like python'
B
' I like python', ' I like python'
C
'I like python', ' I like python'
D
'I like python', 'I like python '
在Python3中,字符串的strip()函数为删除字符串的前后空格,rstrip() 为删除字符串末尾的空格

15.
在Python3中,程序运行返回结果为:
    lists = [1, 1, 2, 3, 4, 5, 6]
lists.remove(1)
lists.append(7)
print(lists)


A
[2,3,4,5,6]
B
[1,2,3,4,5,6]
C
[2,3,4,5,6,7]
D
[1,2,3,4,5,6,7]

16.
在Python3中,下列程序运行结果为:
    tmp = [1, 2, 3, 4, 5, 6]
tmp.insert(-3, 'a')
print(tmp[4])


A、4
B、5
C、3
D、'a'

17.
在Python3中,下列说法正确的是:
    lists = [1, 2, 2, 3, 4, 5]
print(lists.index(2))


A、1
B、2
C、3
D、None

18.
下面有关计算机基本原理的说法中,正确的一项是:()
A
堆栈(stack)在内存中总是由高地址向低地址方向增长的。
B
发生函数调用时,函数的参数总是通过压入堆栈(stack)的方式来传递的。
C
在64位计算机上,Python3代码中的int类型可以表示的最大数值是2^64-1。
D
在任何计算机上,Python3代码中的float类型都没有办法直接表示[0,1]区间内的所有实数。

19.
执行下列选项中的程序,输出结果为False的是()
A
t1 = (1,2,3)
t2 = t1[:]
print(t1 is t2)
B
lis1 = [1,2,3]
lis2 = lis1[:]
print(id(lis1)==id(lis2))
C
s1 = '123'
s2 = '123'
print(s1 is s2)
D
a = 123
b = 123
print(id(a) == id(b))

20.
下面代码运行后,a、b、c、d四个变量的值,描述错误的是?
    import copy
a = [1, 2, 3, 4, ['a', 'b']]
b = a
c = copy.copy(a)
d = copy.deepcopy(a)
a.append(5)
a[4].append('c')

A
a == [1,2, 3, 4, ['a', 'b', 'c'], 5]
B
b == [1,2, 3, 4, ['a', 'b', 'c'], 5]
C
c == [1,2, 3, 4, ['a', 'b', 'c']]
D
d == [1,2, 3, 4, ['a', 'b', 'c']]

21.
执行以下程序,输出结果为()
sizes = ['S','M']
colors = ['white','black']
shirts = [(size,color) for color in colors for size in sizes]
print(shirts)
A
[('S', 'white'), ('S', 'black'), ('M', 'white'), ('M', 'black')]
B
[('S', 'white'), ('M', 'white'), ('S', 'black'), ('M', 'black')]
C
[('S', 'white'), ('M', 'black')]
D
[('white', 'S'), ('black', 'M')]

22.
根据以下程序,下列选项中,说法正确的是()
class Foo():
    def __init__(self):
        pass
    def __getitem__(self,pos):
        return range(0,30,10)[pos]
foo = Foo()
A
foo对象表现得像个序列
B
可以使用len(foo)来查看对象foo的元素个数
C
可以使用for i in foo:print(i)来遍历foo的元素
D
不能使用foo[0]来访问对象foo的第一个元素

23.
已知print_func.py的代码如下:
    print('Hello World!')
print('__name__value: ', __name__)
def main():
    print('This message is from main function')
if __name__ =='__main__':
    main()
print_module.py的代码如下:
    import print_func
print("Done!")
运行print_module.py程序,结果是:
A
Hello World!
__name__ value: print_func
Done!
B
Hello World!
__name__ value: print_module
Done!
C
Hello World!
__name__ value: __main__
Done!
D
Hello World!
__name__ value:
Done!

24.
在Python3中,关于程序运行结果说法正确的是:
    dicts = {}
dicts[([1, 2])] = 'abc'
print(dicts)

A
{([1,2]): 'abc'}
B
{[1,2]: 'abc'}
C
报错
D
其他说法都不正确

25.
根据以下代码,下列选项中,说法正确的是()
class Rectangle:
    __count = 0
    def __init__(self,width,height):
        Rectangle.__count += 1
        self.__width = width
        self.__height = height
    @property
    def area(self):
        return self.__height * self.__width
rectangle = Rectangle(200,100)

A
创建实例对象rectangle后,可在类外使用rectangle.area()来访问area属性
B
area属性为对象的非私有属性,可以访问和修改
C
变量__count的作用是为了统计创建对象的个数
D
因为__width和__height为私有变量,所以在类外不可能访问__width和__height属性

26.
运行下列四个选项的程序,不会抛出异常的是()
A
class Rect:
def __init__(self,width,height):
self.width = width
self.height = height
@property
def area(self):
return self.height* self.width
rect = Rect(10,20)
rect.area()
B
a = 0
def fun():
a += 1
print(a)
fun()
C
class Animal:
def __init__(self,color="白色"):
Animal.color = color
def get_color(self):
print("Animal的颜色为",Animal.color)
class Cat(Animal):
def __init__(self):
pass
cat = Cat()
cat.get_color()
D
class Cat:
def __init__(self,color="白色"):
self.__color = color
cat = Cat("绿色")
print(cat._Cat__color)

27.
根据以下程序,下列选项中,说法正确的是()
class Vector:
    __slots__='x','y'
    def __init__(self):
        pass
class Vector3d(Vector):
    __slots__='x','z'
    def __init__(self):
        pass
vector = Vector()
vector3d = Vector3d()
A
若子类没有定义__slots__属性,则子类可以继承父类的__slots__属性
B
Vector类的实例对象vector会自动获得实例属性x和y
C
Vector3d类的实例对象vector3d最多只能允许属性x和z
D
Vector3d类的实例对象vector3d最多只能允许属性x、y和z

28.
执行以下程序,下列选项中,说法正确的是()
tup = (1,2,[3,4]) ①
tup[2]+=[5,6] ②
A
执行代码②后,变量tup[2]的id发生改变
B
①和②均可以执行而不会抛出异常
C
执行代码②时会抛出异常,最终tup的值为(1,2,[3,4,5,6])
D
执行代码②时会抛出异常,最终tup的值为(1,2,[3,4])
多选题
29.
若 a = (1, 2, 3),下列哪些操作是合法的?
A
a[1:-1]
B
a*3
C
a[2] = 4
D
list(a)
多选题
30.
对于Python类中单下划线_foo、双下划线__foo与__foo__的成员,下列说法正确的是?
A
_foo 不能直接用于’from module import *’
B
__foo解析器用_classname__foo来代替这个名字,以区别和其他类相同的命名
C
__foo__代表python里特殊方法专用的标识
D
__foo 可以直接用于’from module import *’

1.
有如下Python代码段:
    b1=[1,2,3]
b2=[2,3,4]
b3 = [val for val in b1 if val in b2]
print (b3)

上述代码段的运行结果为:()
A
[1,2,3,4]
B
[2]
C
[2,3]
D
程序有误

2.
下列程序运行结果为:
    a=[2, 4, 6, 8, 20,30,40]
print(a[::2])
print(a[-2:])
A
[2, 6, 20, 40] [30, 40]
B
[4, 8, 30] [30, 40]
C
[2, 6, 20, 40] [40]
D
[4, 8, 30] [30]

3.
列表lis=[1,2,3,4,5,6],其切片lis[-1:1:-1]结果为()

A
[6,5]
B
[1,2]
C
[1,2,3,4]
D
[6,5,4,3]

4.
在Python3中,下列程序运行结果为:
    tmp = [1, 2, 3, 4, 5, 6]
print(tmp[5::-2])

A
[5, 3, 1]
B
[6,4,2,0]
C
[6, 4, 2]
D
[2,4,6]

5.
在Python3中,下列语句正确结果为:
    tmp = [2, 1, 5, 4, 7]
print(max(tmp))
print(tmp.index(max(tmp)))


A、7,1
B、5,2
C、7,4
D、7,5

6.
在Python3中,下列程序运行结果为:
    strs = ['a', 'ab', 'abc', 'python']
y = filter(lambda s: len(s) > 2, strs)
tmp = list(map(lambda s: s.upper(), y))
print(tmp)

A
['ABC', 'PYTHON']
B
['abc', 'PYTHON']
C
['abc', 'python']
D
['a', 'ab']

7.
在Python3中,下列程序运行结果为:
    a = [1, 2, 3]
b = [4, 5, 6]
print(a+b)


A
[1, 2, 3]
B
[4, 5, 6]
C
[1, 2, 3, 4, 5, 6]
D
[5, 7, 9]

8.
在Python3中,字符串的变换结果为:
    strs = 'I like python and java'
print(strs.replace('I', 'Your'))
print(strs.replace('a', '*', 2))


A
'Your like python and java','I like python *nd j*v*'
B
'I like python and java','I like python *nd j*v*'
C
'Your like python and java','I like python *nd j*va'
D
'I like python and java','I like python *nd j*va'

9.
执行以下程序,当用户输入0时,输出结果为()
dividend = 1
divide = int(input())
try:
    result = dividend / divide
    print(1,end=" ")
except ZeroDivisionError:
    print(2,end=" ")
except Exception:
    print(3,end=" ")
else:
    print(4) 
A、1 2
B、2 4
C、2 3
D、2

10.
在Python3中,对于以下程序正确的是:
    lists = [1, 2, 3, 4, 5, 6]
print(lists[6:])


A、报错
B、[]
C、[1,2,3,4,5,6]
D、[6]

11.
在Python3中,以下程序结果为:
    one = (1, 2, 3)
two = ('a', 'b')
print(one+two)

A
None
B
报错
C
(1, 2, 3, 'a', 'b')
D
[1, 2, 3, 'a', 'b']

12.
执行下列选项代码,输出[1, {'age': 10}]的是()
A
a = [1,{'age':10}]
b = a
a[1]['age'] = 12
print(b)
B
a = [1,{'age':10}]
b = a[:]
a[1]['age'] = 12
print(b)
C
a = [1,{'age':10}]
b = a.copy()
a[1]['age'] = 12
print(b)
D
import copy
a = [1,{'age':10}]
b = copy.deepcopy(a)
a[1]['age'] = 12
print(b)

13.
下面这段程序的功能是什么?(    )
    def f(a, b):
    if b == 0:
        return a
    else:
        return f(b, a%b)
     
a, b = input(“Enter two natural numbers: ”)
print f(a, b)

A
求AB最大公约数
B
求AB最小公倍数
C
求A%B
D
求A/B

14.
对于下面的python3函数,如果输入的参数n非常大,函数的返回值会趋近于以下哪一个值(选项中的值用Python表达式来表示)()
    import random 
def foo(n):   
        random.seed()
     c1 = 0
     c2 = 0
     for i in range(n):
        x = random.random()
        y = random.random()
        r1 = x * x + y * y
        r2 = (1 - x) * (1 - x) + (1 - y) * (1 - y)
        if r1 <= 1 and r2 <= 1:
           c1 += 1
         else:
           c2 += 1
    return   c1 / c2


A、4 / 3
B、(math.pi - 2) / (4 - math.pi)
C、math.e ** (6 / 21)
D、math.tan(53 / 180 * math.pi)

15.
Python2 中,以下不能在list中添加新元素的方法是()
A、append()
B、add()
C、extend()
D、insert()

16.
执行下列程序,输出结果为()
def fun(a,*,b):
    print(b)
fun(1,2,3,4)
A
[2,3,4]
B
[3,4]
C
报错
D
4

17.
What gets printed?()
    kvps = { '1' : 1, '2' : 2 }
theCopy = kvps.copy()
kvps['1'] = 5
sum = kvps['1'] + theCopy['1']
print sum


A、1
B、2
C、6
D、10
E、An exception is thrown

18.
在python3中,下列程序结果为:
    dicts = {'one': 1, 'two': 2, 'three': 3}
print(dicts['one'])
print(dicts['four'])


A、1,[]
B、1,{}
C、1,报错
D、1,None

19.
以下程序输出为:
info = {'name':'班长', 'id':100, 'sex':'f', 'address':'北京'}
age = info.get('age')
print(age)
age=info.get('age',18)
print(age)
A
None 18
B
None None
C
编译错误
D
运行错误

20.
执行下列选项的程序,会抛出异常的是()

A
a = 1
b = 2
a,b = b,a
B
a,*b,c = range(5)
print(a,b,c)
C
lis = ['1','2']
a,b = list(map(int,lis))
print(a,b)
D
tup = (1,(2,3))
a,b,c = tup
print(a,b,c)

21.
已知a = [1, 2, 3]和b = [1, 2, 4],那么id(a[1])==id(b[1])的执行结果 ()
A
True
B
False

22.
在python中,使用open方法打开文件,语法如下:
open(文件名,访问模式)
如果以二进制格式打开一个文件用于追加,则访问模式为:
A、rb
B、wb
C、ab
D、a

23.
在Python3中,以下字符串操作结果为:
    strs = 'I like python'
one = strs.find('a')
print(one)
two = strs.index('a')
print(two)

A、None, 报错
B、报错,报错
C、-1, None
D、-1, 报错

24.执行以下程序,输出结果为()
def outer(fn):
    print('outer')
    def inner():
        print('inner')
        return fn
    return inner
@outer
def fun():
    print('fun')
A、outer
B、inner
C、fun
D、因为没有调用任何函数,所以没有输出结果

25.
当使用import导入模块时,按python查找模块的不同顺序可划分为以下几种:
①环境变量中的PYTHONPATH
②内建模块
③python安装路径
④当前路径,即执行Python脚本文件所在的路径
其中查找顺序正确的一组是()
A
①④②③
B
②①④③
C
②④①③
D
①②③④

26.
下列程序打印结果为()
    import re 
str1 = "Python's features" 
str2 = re.match( r'(.*)on(.*?) .*', str1, re.M|re.I)
print str2.group(1)


A、Python
B、Pyth
C、thon’s
D、Python‘s features

27.
有如下类定义,下列描述错误的是?
    class A(object):
    pass
 
class B(A):
    pass
 
b = B()

A
isinstance(b, A) == True
B
isinstance(b, object) == True
C
issubclass(B, A) == True
D
issubclass(b, B) == True

28.
what gets printed? Assuming python version 2.x()
    print type(1/2)

A、<type 'int'>
B、<type 'number'>
C、<type 'float'>
D、<type 'double'>
E、<type 'tuple'>

29.
以下这段代码的输出结果为()
    import numpy as np
a = np.repeat(np.arange(5).reshape([1,-1]),10,axis = 0)+10.0
b = np.random.randint(5, size= a.shape)
c = np.argmin(a*b, axis=1)
b = np.zeros(a.shape)
b[np.arange(b.shape[0]), c] = 1
print b


A
Hello World!
B
一个 shape = (5,10) 的随机整数矩阵
C
一个 shape = (5,10) 的 one-hot 矩阵
D
一个 shape = (10,5) 的 one-hot 矩阵
多选题
30.
对于python中__new__和__init__的区别,下列说法正确的是?
A
__new__是一个静态方法,而__init__是一个实例方法
B
__new__方法会返回一个创建的实例,而__init__什么都不返回
C
只有在__new__返回一个cls的实例时,后面的__init__才能被调用
D
当创建一个新实例时调用__new__,初始化一个实例时用__init__

1.
执行以下程序,输出结果为()
def fun(a=(),b=[]):
    a += (1,)
    b.append(1)
    return a,b
fun()
print(fun())
A
((1,), [1, 1])
B
((1,1), [1, 1])
C
((1,), [1])
D
((1,1), [1])


 

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

斜躺青年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值