2019年python面试题一
1.which of the following is invalid?
a)_a=1
b)__a=1
c)__str__=1
d)none of the mentioned
答案:(d)
2.which of the following is not a keyword?
a)eval
b)assert
c)nonlocal
d)pass
答案:a
3.which of the following is an invalid statement?
a)abc = 1,000,000
b)a b c = 1000 2000 3000
c)a,b,c = 1000,2000,3000
d)a_b_c = 1,000,000
答案:b
4.what is the output of this expression,3*1**3?
a)27
b)9
c)3
d)1
答案:c
5.which of the following is incorrect?
a)float('inf')
b)float('nan')
c)float('56'+'78')
d)float('12+34')
答案:d
6.what dose 3^4 evaluate to?
a)81
b)12
c)0.75
d)7
答案:d
7.Consider the expression given below.The value of X is:X=2+9*((3*12)-8)/10?
a)30.0
b)30.8
c)28.4
d)27.2
答案:d
8.what is the output of the following?
i = 5
while True:
if i%0o11 == 0:
break
print(i)
i += 1
a)5 6 7 8 9
b)5 6 7 8
c)5 6
d)error
答案:b
9.what is the output of the following?
print("abcdefcdghcd".split("cd",2))
a)["ab","ef","ghcd"]
b)["ab","efcdghcd"]
c)["abcdef","ghcd"]
d)none of the mentioned
答案:a
10.what dose the following piece of code do?
print(list(zip((1,2,3),("a"),('xxx','yyy'))))
print(list(zip((2,4),('b','c'),('yy','xx'))))
a)[(1,2,3),('a'),('xxx','yyy')]
[(2,4),('b','c'),('yy','xx')]
b)[(1, 'a', 'xxx'),(2,'','yyy'),(3,'','')]
[(2,'b','yy'),(4,'c','xx')]
c)Syntax error
d)[(1, 'a', 'xxx')]
[(2, 'b', 'yy'), (4, 'c', 'xx')]
答案:d
11. What is the output of the code shown?
s = ['pune','mumbai','delhi']
[(w.upper(), len(w)) for w in s]
a)error
b)['PUNE', 4,'MUMBAI', 6,'DELHI', 5]
c)[PUNE, 4,MUMBAI, 6,DELHI, 5]
d)[('PUNE', 4), ('MUMBAI', 6), ('DELHI', 5)]
答案:d
12.which of the following lines of code will result in an error?
a)s = {abs}
b)s = {4,'abc',(1,2)}
c)s = {2,2.2,3,'xyz'}
d)s = {san}
答案:d
13.Suppose d={'john':40,'peter',45},to delete the entry for "john" what command do?
a)d.delete('john':40)
b)d.delete('john')
c)del d['john']
d)del d['john':40]
答案:c
14.what is the output of the code shown below?
import re
s='abc123 xyz666 lmn-11 def77'
re.sub(r'\b([a-z]+)(\d+)',r'\2\1',s)
a)'123abc 666xyz lmn-11 def77'
b)'77def lmn-11 666xyz 123abc'
c)'abc123','xyz666','lmn-11','def77'
d)'abc123 xyz666 lmn-11 def77'
答案:a
15.what is the output of the following piece of code?
a)13
b)7
c)infinite loop
d)17
答案:d