Python100經(jīng)典練習題.pdf(附答案)


點擊上方藍字關(guān)注我們


點擊上方“印象python”,選擇“星標”公眾號
重磅干貨,第一時間送達!

作者:Python蕓蕓
鏈接:https://www.jianshu.com/p/232d3798af55
1:Python有哪些特點和優(yōu)點?
具有動態(tài)特性
面向?qū)ο?br>簡明簡單
開源
具有強大的社區(qū)支持
2:深拷貝和淺拷貝之間的區(qū)別是什么?
>>> import copy>>> b=copy.deepcopy(a)

>>> b=copy.copy(a)

3. 列表和元組之間的區(qū)別是?
>>> mylist=[1,3,3]>>> mylist[1]=2>>> mytuple=(1,3,3)>>> mytuple[1]=2Traceback (most recent call last):File "", line 1, in mytuple[1]=2
TypeError: ‘tuple’ object does not support item assignment
4. 解釋一下Python中的三元運算子
[on true] if [expression] else [on false]
下面是使用它的方法:
>>> a,b=2,3>>> min=a if a>>> min運行結(jié)果:2>>> print("Hi") if a運行結(jié)果:Hi
5. 在Python中如何實現(xiàn)多線程?
6. 解釋一下Python中的繼承
單繼承:一個類繼承自單個基類
多繼承:一個類繼承自多個基類
多級繼承:一個類繼承自單個基類,后者則繼承自另一個基類
分層繼承:多個類繼承自單個基類
混合繼承:兩種或多種類型繼承的混合
7. 什么是Flask?
8. 在Python中是如何管理內(nèi)存的?
9. 解釋Python中的help()和dir()函數(shù)
>>> import copy>>> help(copy.copy)
Help on function copy in module copy:copy(x)?Shallow?copy?operation?on?arbitrary?Python?objects.?See?the?module’s?__doc__?string?for?more?info.
>>> dir(copy.copy)
[‘__annotations__’, ‘__call__’, ‘__class__’, ‘__closure__’, ‘__code__’, ‘__defaults__’, ‘__delattr__’, ‘__dict__’, ‘__dir__’, ‘__doc__’, ‘__eq__’, ‘__format__’, ‘__ge__’, ‘__get__’, ‘__getattribute__’, ‘__globals__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__init_subclass__’, ‘__kwdefaults__’, ‘__le__’, ‘__lt__’, ‘__module__’, ‘__name__’, ‘__ne__’, ‘__new__’, ‘__qualname__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__repr__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subclasshook__’]
10. 當退出Python時,是否釋放全部內(nèi)存?
11. 什么是猴子補?。?/strong>
>>> class A:def func(self):print("Hi")>>> def monkey(self):print "Hi, monkey">>> m.A.func = monkey>>> a = m.A()>>> a.func()
Hi, Monkey
12. Python中的字典是什么?
>>> roots={25:5,16:4,9:3,4:2,1:1}>>> type(roots)>>> roots[9]
3
>>> roots={x**2:x for x in range(5,0,-1)}>>> roots
{25: 5, 16: 4, 9: 3, 4: 2, 1: 1}
13. 請解釋使用args和*kwargs的含義
>>> def func(*args):for i in args:print(i)>>> func(3,2,1,4,7)
3
2
1
4
7
>>> def func(**kwargs):for i in kwargs:print(i,kwargs[i])>>> func(a=1,b=2,c=7)
a.1
b.2c.7
14. 請寫一個Python邏輯,計算一個文件中的大寫字母數(shù)量
>>> import os>>> os.chdir('C:\\Users\\lifei\\Desktop')>>> with open('Today.txt') as today:count=0for i in today.read():if i.isupper():count+=1print(count)
26
15. 什么是負索引?
>>> mylist=[0,1,2,3,4,5,6,7,8]
>>> mylist[-3]
6
>>> mylist[-6:-1]
[3, 4, 5, 6, 7]
16. 如何以就地操作方式打亂一個列表的元素?
>>> from random import shuffle>>> shuffle(mylist)>>> mylist
復制代碼
[3, 4, 8, 0, 5, 7, 6, 2, 1]
17. 解釋Python中的join()和split()函數(shù)
>>> ','.join('12345')
‘1,2,3,4,5’
>>> '1,2,3,4,5'.split(',')
[‘1’, ‘2’, ‘3’, ‘4’, ‘5’]
18. Python區(qū)分大小寫嗎?
>>> myname='Ayushi'>>> MynameTraceback (most recent call last):File "", line 1, in
Myname
NameError: name ‘Myname’ is not defined
19. Python中的標識符長度能有多長?
其余部分可以使用 A-Z/a-z/0-9
區(qū)分大小寫
關(guān)鍵字不能作為標識符,Python中共有如下關(guān)鍵字:

20. 怎么移除一個字符串中的前導空格?
>>> ' Ayushi '.lstrip()
‘Ayushi ’
>>> ' Ayushi '.rstrip()
‘ Ayushi’
21. 怎樣將字符串轉(zhuǎn)換為小寫?
>>> 'AyuShi'.lower()
‘a(chǎn)yushi’
>>> 'AyuShi'.upper()
‘AYUSHI’
>>> 'AyuShi'.isupper()False>>> 'AYUSHI'.isupper()True>>> 'ayushi'.islower()True>>> '@yu$hi'.islower()True>>> '@YU$HI'.isupper()True
>>> 'The Corpse Bride'.istitle()True
22. Python中的pass語句是什么?
>>> def func(*args):pass>>>
>>> for i in range(7):if i==3: breakprint(i)
0
1
2
>>> for i in range(7):if i==3: continueprint(i)
0
1
2
4
5
6
23. Python中的閉包是什么?
>>> def A(x):def B():print(x)return B>>> A(7)()
7
24. 解釋一下Python中的//,%和 ** 運算符
>>> 7//23
>>> 2**101024
>>> 13%76>>> 3.5%1.50.5
25. 在Python中有多少種運算符?解釋一下算數(shù)運算符。
>>> 7+815
>>> 7-8-1
>>> 7*856
>>> 7/80.875>>> 1/11.0
26. 解釋一下Python中的關(guān)系運算符
1.小于號(<),如果左邊的值較小,則返回True。
>>> 'hi'<'Hi'False
>>> 1.1+2.2>3.3True
>>> 3.0<=3True
>>> True>=FalseTrue
>>> {1,3,2,2}=={1,2,3}True
>>> True!=0.1True>>> False!=0.1True
27. 解釋一下Python中的賦值運算符
>>> a=7>>> a+=1>>> a8>>> a-=1>>> a7>>> a*=2>>> a14>>> a/=2>>> a7.0>>> a**=2>>> a49>>> a//=3>>> a16.0>>> a%=4>>> a0.0
28. 解釋一下Python中的邏輯運算符
>>> False and TrueFalse>>> 7<7 or TrueTrue>>> not 2==2False
29. 解釋一下Python中的成員運算符
>>> 'me' in 'disappointment'True>>> 'us' not in 'disappointment'True
30. 解釋一下Python中的身份運算符
>>> 10 is '10'False>>> True is not FalseTrue
31. 講講Python中的位運算符
>>> 0b110 & 0b0102
>>> 3|23
>>> 3^21
>>> ~2-3
>>> 1<<24
>>> 4>>21
32. 在Python中如何使用多進制數(shù)字?
>>> int(0b1010)10
>>> bin(0xf)‘0b1111’
>>> oct(8)‘0o10’
>>> hex(16)‘0x10’>>> hex(15)‘0xf’
33. 怎樣獲取字典中所有鍵的列表?
>>> mydict={'a':1,'b':2,'c':3,'e':5}>>> mydict.keys()dict_keys(['a', 'b', 'c', 'e'])
34. 為何不建議以下劃線作為標識符的開頭
35. 怎樣聲明多個變量并賦值?
>>> a,b,c=3,4,5 #This assigns 3, 4, and 5 to a, b, and c respectively>>> a=b=c=3 #This assigns 3 to a, b, and c
36. 元組的解封裝是什么?
>>> mytuple=3,4,5>>> mytuple(3, 4, 5)
>>> x,y,z=mytuple>>> x+y+z

掃描二維碼
獲取更多精彩
印象python

點個在看你最好看

評論
圖片
表情
