程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

25 basic Python questions (including answers)

編輯:Python

1 The program that executes the following options , What throws an exception is :
A.

s1 = 'aabbcc'
s2 = 'abc'
count = s1.count(s2)
if count > 0 :
print('s2 yes s1 The string of ')
else:
print('s2 No s1 The string of ')

B.

s1 = 'aabbcc'
s2 = 'abc'
index = s1.index(s2)
if index > -1:
print('s2 yes s1 The string of ')
else:
print('s2 No s1 The string of ')

C.

s1 = 'aabbcc'
s2 = 'abc'
find = s1.find(s2)
if find != -1 :
print('s2 yes s1 The string of ')
else:
print('s2 No s1 The string of ')

D.

s1 = 'aabbcc'
s2 = 'abc'
if s2 in s1:
print('s2 yes s1 The string of ')
else:
print('s2 No s1 The string of ')

2 For the following code , The right description is :
list = [‘1’, ‘2’, ‘3’, ‘4’, ‘5’]
print(list[10:])
A. Lead to IndexError B. Output [‘1’, ‘2’, ‘3’, ‘4’, ‘5’]
C. Compile error D. Output []

3 Python Execute the following command from the command line , The result is :

>>> f = (lambda x, y ,z="Win": x+y+z)
>>> f("You")

A. Report errors B.‘YouWin’ C.‘You Win’ D. ‘You+Win’

4 The output of the following code is :

def add(n):
return lambda x: x+n
f = add(1)
print(f(2))

A.2 B.3 C.4 D. 5

5 The output of the following code is :

L = [lambda x: x**2,lambda x: x**3,lambda x: x**4]
print(L[1](2))

A. Report errors B.4 C.8 D. 16

6 The output of the following code is :
str1=‘abc’
str1[2]=‘d’
print(str1)
A. Report errors B.abc C.adc D. abd

7 Python Execute the following command from the command line , The result is :

>>>float(None)

A. Report errors B.0 C.0.0 D. inf

8 Python Execute the following command from the command line , The result is :

>>>print(3, 'boys')

A. Report errors B.3boys C.3 boys D. 3 Line break boys

9 The output of the following code is :
a=[1,2,3,4,5]
print(a[-3:])
A. Report errors B.[2, 3, 4, 5] C.[4, 5] D. [3, 4, 5]

10 The output of the following code is :
strs = ’ I like python ’
one = strs.split(’ ‘)
two = strs.split()
print(one)
print(two)
A. Report errors B.[’‘, ‘I’, ‘like’, ‘python’, ‘’] [‘I’, ‘like’, ‘python’]
C.[’‘, ‘I’, ‘like’, ‘python’, ‘’][’', ‘I’, ‘like’, ‘python’, ‘’] D. [‘I’, ‘like’, ‘python’] [‘I’, ‘like’, ‘python’]

11 The output of the following code is :
dicts = {}
dicts[([1, 2])] = ‘abc’
print(dicts)
A.{([1,2]): ‘abc’} B.{[1,2]: ‘abc’}
C. Report errors D. None of the other statements are true

12 stay Python3 In the environment of , The following program is to find out 1-10 Odd numbers in the middle , Then fill in... At the horizontal line :

for i in range(1, 11):
if i % 2 == 0:
______
print(i)

A.break B.yield C.continue D.flag

13 The output of the following code is :
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]

14 The output of the following code is :
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]

15 Python Execute the following command from the command line , The result is :

tup = (('onion','apple'),('tomato','pear'))
for _,thing in tup:
print(thing)

A. Report errors B.apple Line break pear
C.onion Line break tomato D. (‘onion’,‘apple’) Line break (‘tomato’,‘pear’)

16 The output of the following code is :

def hhh(a,*,b,c):
print(a,b,c)
hhh(1,2,3)

A. Report errors B.1 2 3
C.1 D.2 3

17 Python Execute the following command from the command line , The result is :

>>>2+3
>>>4*_

A. Report errors B. 4 C.5 D. 20

18 The output of the following code is :
print(int(6.5))
print(int(‘6.5’))
A.7 7 B.7 Report errors C.6 6 D. 6 Report errors

19 Execute the following code , In the following options , It's true that ()
a=b=[1,2]
a+=[3]
b=b+[3]
A. First line a、b The address of is different B.a Your address has changed
C. Final b The value of is [1, 2, 3, 3] D. Final a and b The same address

20 The following options are equivalent to False Yes. :
A.{‘’} B. ({},) C. ([]) D. [[]]

21 Run the code snippet below , The output is ( ).

for i in range(10):
for t in range(5):
s = i + t
print(s)

A.50 B. 36 C. 15 D. 13

22 The output of the following code is :

l_ids=['a','b','c']
for n,i in enumerate(l_ids,1):
print(n,i,end=' ')

A.0 a B.0 b 1 c
C.1 b 2 c D.1 a 2 b 3 c

23 a=[1,2,3][False];print(a) As the result of the :
A. Report errors B.1 C.2 D.3

24 i=1;print(++i) As the result of the :
A. Infinite loop B. Report errors C.1 D.2

25 print(float(‘12E3’)) As the result of the :
A. Report errors B.12.3 C.12000 D.12000.0

answer :BDABC AACDB CCADB ADDCC DDBCD


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved