一、基础篇
- 想要像类似执行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:C -
print(100 - 25 * 3 % 4) 打印的结果是?
A.1 B.97 C.25 D.82KEY:B
-
下列语句中,非法的是_____?
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:1 -
>>> a = lambda x: x+1
>>> a(1)
输出结果是_______?
KEY:2 -
>>> chr(65)
输出结果是_______?
KEY:'A' -
>>> ord("A")
输出结果是_______?
KEY:65 -
>>> n = 8
>>> n.bit_length()
结果是_______?
KEY:4 - >>> hash(1.0) == hash(1) 输出结果是? KEY:True
-
>>> a = 0x11
>>> b = 0o11
>>> c = 0b11
a + b + c 的值为_____?
KEY:29 -
>>> 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:Alexdemo.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]