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

Python初級試題25道(含答案)

編輯:Python

1 執行下列選項的程序,會拋出異常的是:
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的子串')

2 對於以下代碼,描述正確的是:
list = [‘1’, ‘2’, ‘3’, ‘4’, ‘5’]
print(list[10:])
A.導致 IndexError B.輸出[‘1’, ‘2’, ‘3’, ‘4’, ‘5’]
C.編譯錯誤 D.輸出[]

3 Python命令行執行下面的命令,結果為:

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

A.報錯 B.‘YouWin’ C.‘You Win’ D. ‘You+Win’

4 以下代碼的輸出結果為:

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

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

5 以下代碼的輸出結果為:

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

A.報錯 B.4 C.8 D. 16

6 以下代碼的輸出結果為:
str1=‘abc’
str1[2]=‘d’
print(str1)
A.報錯 B.abc C.adc D. abd

7 Python命令行執行下面的命令,結果為:

>>>float(None)

A.報錯 B.0 C.0.0 D. inf

8 Python命令行執行下面的命令,結果為:

>>>print(3, 'boys')

A.報錯 B.3boys C.3 boys D. 3換行boys

9 以下代碼的輸出結果為:
a=[1,2,3,4,5]
print(a[-3:])
A.報錯 B.[2, 3, 4, 5] C.[4, 5] D. [3, 4, 5]

10 以下代碼的輸出結果為:
strs = ’ I like python ’
one = strs.split(’ ‘)
two = strs.split()
print(one)
print(two)
A.報錯 B.[’‘, ‘I’, ‘like’, ‘python’, ‘’] [‘I’, ‘like’, ‘python’]
C.[’‘, ‘I’, ‘like’, ‘python’, ‘’][’', ‘I’, ‘like’, ‘python’, ‘’] D. [‘I’, ‘like’, ‘python’] [‘I’, ‘like’, ‘python’]

11 以下代碼的輸出結果為:
dicts = {}
dicts[([1, 2])] = ‘abc’
print(dicts)
A.{([1,2]): ‘abc’} B.{[1,2]: ‘abc’}
C.報錯 D.其他說法都不正確

12 在Python3的環境中,如下程序是實現找出1-10中奇數,則橫線處應填寫:

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

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

13 以下代碼的輸出結果為:
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 以下代碼的輸出結果為:
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命令行執行下面的命令,結果為:

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

A.報錯 B.apple換行pear
C.onion換行tomato D. (‘onion’,‘apple’)換行(‘tomato’,‘pear’)

16 以下代碼的輸出結果為:

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

A.報錯 B.1 2 3
C.1 D.2 3

17 Python命令行執行下面的命令,結果為:

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

A.報錯 B. 4 C.5 D. 20

18 以下代碼的輸出結果為:
print(int(6.5))
print(int(‘6.5’))
A.7 7 B.7 報錯 C.6 6 D. 6 報錯

19 執行以下代碼,下列選項中,說法正確的是()
a=b=[1,2]
a+=[3]
b=b+[3]
A.第一行時a、b的地址不同 B.a的地址發生過改變
C.最終b的值為[1, 2, 3, 3] D.最終a和b的地址相同

20 下列選項中相當於False的是:
A.{‘’} B. ({},) C. ([]) D. [[]]

21 運行下方代碼段,輸出的是( )。

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

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

22 以下代碼的輸出結果為:

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)的結果為:
A.報錯 B.1 C.2 D.3

24 i=1;print(++i)的結果為:
A.無限循環 B.報錯 C.1 D.2

25 print(float(‘12E3’))的結果為:
A.報錯 B.12.3 C.12000 D.12000.0

答案:BDABC AACDB CCADB ADDCC DDBCD


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