1、基礎篇
- 想要像相似執行shell腳本同樣執行Python腳本,須要在py文件開頭加上什麼?KEY:#!/usr/bin/env python
- Python解釋器在加載 .py 文件中的代碼時,會對內容進行編碼(默認ascill),咱們應該選擇什麼編碼?如何配置? KEY:UTF8 | # -*- coding: utf-8 -*-
- Python中使用什麼符號作註釋,多行註釋使用什麼? KEY:# | 三個連續的單引號或三個連續的雙引號
- Python中的單引號和雙引號有無區別? KEY:無
- Python中使用什麼命令導入模塊? KEY:import modulename
- py文件在執行過程當中會自動生成一個與其同名的 .pyc 文件,它是什麼?有什麼用?KEY:pyc是由py文件通過編譯後二進制文件,py文件變成pyc文件後,加載的速度有所提升,並且pyc是一種跨平臺的字節碼,是由python的虛擬機來執行的.
- 按Python中的變量定義,如下哪一個是合法變量? [A: _name1 B:123 C:class D:abc-] KEY:A
-
Python使用縮進做爲語法邊界,通常建議怎樣縮進?
A.TAB B.兩個空格 C.四個空格 D.八個空格
KEY:Cpython -
print(100 - 25 * 3 % 4) 打印的結果是?
A.1 B.97 C.25 D.82gitKEY:Bshell
-
下列語句中,非法的是_____?
A.x=y=1
B.x=(y=1)
C.x,y=y,x
D.x=1;y=1
KEY:B函數 -
>>> n = 3
>>> a = 1 if n > 2 else 3
>>> a
輸出結果是_______?
KEY:1post -
>>> a = lambda x: x+1
>>> a(1)
輸出結果是_______?
KEY:2編碼 -
>>> chr(65)
輸出結果是_______?
KEY:'A'blog -
>>> ord("A")
輸出結果是_______?
KEY:65ip -
>>> n = 8
>>> n.bit_length()
結果是_______?
KEY:4utf-8 - >>> hash(1.0) == hash(1) 輸出結果是? KEY:True
-
>>> a = 0x11
>>> b = 0o11
>>> c = 0b11
a + b + c 的值爲_____?
KEY:29ci -
>>> print('Alex'.center(6, '*'))
結果是_______?
KEY:'*Alex*' -
>>> list1 = ["Alex", "is", "handsome"]
>>> "_".join(list1)
輸出結果是_______?
KEY:'Alex_is_handsome' -
>>> 'www.oldboyedu.com'.replace('w', '*', 1)
結果是_______?
KEY:'*ww.oldboyedu.com' -
>>> 'www.oldboyedu.com'.split('.', 1)
結果是_______?
KEY:['www', 'oldboyedu.com'] -
>>> 'www.oldboyedu.com'.partition('.')
結果是_______?
KEY:('www', '.', 'oldboyedu.com') -
>>> 'www.oldboyedu.com'.strip('zaw.')
結果是_______?
KEY:'oldboyedu.com' -
>>> list1 = [4,1,5,3,2]
>>> list2 = list1.sort()
>>> list2
結果是_______?
KEY:None -
>>> list1 = [4,1,5,3,2]
>>> list2 = sorted(list1)
>>> list2
輸出結果是_______?
KEY:[1, 2, 3, 4, 5] -
>>> list2 = sorted(list1, reverse=True)
>>> list2
輸出結果是_______?
KEY:[5, 4, 3, 2, 1] -
>>> list1 = [1, 3, 5, 2, 4]
>>> list1 = list1[::-1]
>>> list1
結果是?
KEY:[4, 2, 5, 3, 1] -
>>>list1=[[]]*2
>>>list1
[[], []]
>>>id(list1[0])==id(list1[1])
結果是?
KEY:True(列表複製其實複製的是引用) -
>>>list1=[[] for i in range(2)]
>>>list1
[[], []]
>>>id(list1[0])==id(list1[1])
結果是?
KEY:False(從新生成了列表) -
>>> list1 = [1, 2, 3, 6, 7]
>>> min(list1, key=lambda x: x%2)
結果是_______?
KEY:2 -
>>> list1 = [1, 2, 3, 6, 7]
>>> max(list1, key=lambda x: x%2)
結果是_______?
KEY:1 -
>>> list1 = [1, 3, 3, 5, 7]
>>> set(list1)
結果是?
KEY:{1, 3, 5, 7} -
>>> divmod(99, 2)
結果是?
KEY:(49,1) -
>>>num="四"
>>>num.isdigit()
False
>>>num._______()
True
_______ 上應填?
KEY:isnumeric -
>>> result = 1 if 'a'>'b' else 2
>>> result
結果是?
KEY:2 -
>>> dict1 = {"a": 1, "b": 2}
>>> result = dict1.get("c")
>>> print(result)
結果是?
KEY:None -
>>> list1 = [1, 3, 2, 6, 5]
>>> list1.sort(_______)
>>> list1
[6, 5, 3, 2, 1]
_______ 上應填?
KEY:reverse=True -
>>> list1=[1, 2, 3]
>>> list2=list1.reverse()
>>> print(list2)打印的結果爲_______?
KEY:None -
>>> list1=[1, 2, 3]
>>> list2=list1_______
>>> list2
[3, 2, 1]_______ 上應填寫什麼內容?
KEY:[::-1]
-
下面選項中,不能建立字典的語句是( )
A.dict1 = {}
B.dict2 = {1: 2}
C.dict3 = {[1]: 2}
D.dict4 = {(1): 2}
KEY:C -
>>> dict1 = {'a': 1,'b': 2}
>>> dict1.setdefault('c', 3)
>>> dict1['c']
結果爲______?
KEY:3 -
>>> dict1 = {"a": 1, "b": 2}
>>> list(dict1)上述代碼的輸出結果是_______?
KEY:["a", "b"] -
>>> nums={1, 2, 2, 3, 4, 4, 5}
>>> len(nums)
結果是_____?
KEY:5 -
for i in range(2):
print(i)
for j in range(4, 6):
print(j)上述代碼執行的結果是____?
A:12456 B:01456 C:0145 D:2456
KEY:C -
>>> list1 = [1, 3, 5, 7]
>>> for i in list1:
... if i > 6:
... break
... else:
... print(i, end="")
... else:
... print("over", end="")
上述代碼輸出的結果是_______?
KEY:135 -
>>> import copy
>>> a = [1, 2, 3, ["a", "b", "c"]]
>>> b = a
>>> c = copy.copy(a)
>>> d = copy.deepcopy(a)
>>> (id(a) == id(b), id(a) == id(c), id(a) == id(d), id(a[0]) == id(c[0]), id(a[0]) == id(d[0]), id(a[3]) == id(c[3]), id(a[3]) == id(d[3]))
結果爲________?A:(True, True, False, True, True, True, True)
B:(True, False, False, True, True, True, False)
C:(True, False, False, False, False, False, False)
D:(True, True, False, True, True, True, False)
KEY:B -
>>> list1 = [1, 3, 5, 7, 9]
>>> a = _____(1, 3)
>>> list1[1:3]
[3, 5]
>>> list1[a]
[3, 5]
_______ 上應填?
KEY:slice -
>>> a = {1, 2, 3}
>>> b = {3, 4, 5}
>>> a&b結果是_______?
KEY:{3} -
>>> a = {1, 2, 3}
>>> b = {3, 4, 5}
>>> a|b結果是_______?
KEY:{1, 2, 3, 4, 5} -
>>> a = {1, 2, 3}
>>> b = {2, 3, 4}
>>> a.update(b)
>>> a
結果是_______?
KEY:{1, 2, 3, 4} -
python my.py a1 a2 形式運行腳本時,經過 from sys import argv 如何得到參數a2的值?
A.argv[0] B.argv[1] C.argv[2] D.argv[3]
KEY:C -
如下哪一個函數的參數定義非法?
A.def myfunc(*args):
B.def myfunc(arg1=1):
C.def myfunc(*args, a=1):
D.def myfunc(a=1, **args):KEY:D
-
num = 10
def func():
num = 5
func()
print(num)
輸出的結果是_____?
KEY:10 -
num = 10
def fun():
num = 5
print(fun())
輸出的結果是_____?
KEY:None -
def func1():
for i in range(1, 5):
return i
def func2():
for i in range(1, 5):
yield i表達式 func1()+sum(func2()) 的值爲____?
KEY:11 -
表達式 issubclass(bool, int) 的值爲____?
KEY:True -
表達式 True + False 的值爲____?
KEY:1 -
>>> f=open('test.txt','r')
>>> print(f.read())
name:Alex>>> f.seek(5)
>>> print(f.read())
打印的結果是_____?KEY:Alex
-
>>> list1 = [1, 3, 5]
>>> list2 = list(map(lambda x: x + 1, list1))
>>> print(list2)打印的結果是_______?
KEY:[2, 4, 6] -
>>> list1 = [11, 33, 55]
>>> list2 = list(filter(lambda x: x > 22, list1))
>>> print(list2)打印的結果是_______?
KEY:[33, 55] -
>>> from functools import reduce
>>> reduce(lambda x,y : x if x < y else y, [44,11,22,7,31])
上述代碼的輸出結果爲______?KEY:7
-
>>> from functools import reduce
>>> reduce(lambda x, y:x+y, [1, 2, 3, 4, 5],1)
結果是_______?
KEY:16 -
>>> file_path = "D:\Alex\demo.py"
>>> os.path.dirname(file_path)
輸出結果是_______?
KEY:'D:\Alex' -
>>> import re
>>> ret=re.match('\d', 'a1b2c3')
>>> print(ret)
結果是_______?
A:None B:1 C:123 D:[]
KEY:A -
>>> list1 = list(range(1, 10, 2))>>> list1結果是_______?KEY:[1, 3, 5, 7, 9]