中文,免费,零起点,完整示例,基于最新的Python 3版本。https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000
一、选择题
1. Python中单下划线_foo与双下划线__foo与__foo__的成员,下列说法正确的是? A B C
D. __foo 可以直接用于’from module import *’
解析:https://www.nowcoder.com/profile/3129084/test/18549953/144541#summary
2. 在Python 2.7中,下列哪种是Unicode编码的书写方式? 正确答案: C
A. a = ‘中文’
B. a = r‘中文’
C. a = u’中文’
D. a = b’中文’
3. 从运行层面上来看,从四个选项选出不同的一个。正确答案: B
A. JAVA B. Python C. objectC D. C#
解析:https://www.nowcoder.com/test/question/done?tid=18551803&qid=4856#referAnchor
4. 协程
https://www.cnblogs.com/beiluowuzheng/p/9064152.html
http://python.jobbole.com/87156/
5. 以下不能创建一个字典的语句是 正确答案: C
A. dict1 = {}
B. dict2 = { 3 : 5 }
C. dict3 = {[1,2,3]: “uestc”} 字典的键名是不可变类型,列表是可变的数据类型(可以增加或删除项目)。所以,列表中的项目不能用来作为字典的键。
D. dict4 = {(1,2,3): “uestc”}
6. 下列哪个语句在Python中是非法的? 正确答案:B
A. x = y = z = 1
B. x = (y = z + 1) 赋值语句没有返回值,不能用于赋值。
C. x, y = y, x
D. x += y
7. 编码与解码顺序
字符串编译的过程:gbk==>unicode==>utf16==>url解码
字符串解码顺序为:url解码==>utf16==>unicode==>gbk
8.下列哪种不是Python元组的定义方式? 正确答案: A
A. (1) B. (1, ) C. (1, 2) D. (1, 2, (3, 4))
解析:
![](https://img2018.cnblogs.com/blog/1408256/201809/1408256-20180916211659141-1911085808.png)
二、代码小题
1. Assuming the filename for the code below is /usr/lib/python/person.py,and the program is run as: python /usr/lib/python/person.py,What gets printed?(D)
1 class Person: 2 def __init__(self): 3 pass 4 def getAge(self): 5 print(__name__) 6 p = Person() 7 p.getAge()
A. Person
B. getAge
C. usr.lib.python.person
D. main E.An exception is thrown
解析:https://www.nowcoder.com/profile/3129084/test/18549953/141979#summary
参考:https://blog.csdn.net/iamoldpan/article/details/78077983
2. 下列代码执行结果是什么? D
x = 1 def change(a): x += 1 print (x) change(x)
A. 1 B. 2 C. 3 D. 报错
解析:https://www.nowcoder.com/test/question/done?tid=18551803&qid=144521#summary
3. 有如下函数定义,执行结果正确的是? A
def dec(f): n = 3 def wrapper(*args,**kw): return f(*args,**kw) * n return wrapper @dec def foo(n): return n * 2
A. foo(2) == 12 B. foo(3) == 12 C. foo(2) == 6 D. foo(3) == 6
解析:https://www.nowcoder.com/test/question/done?tid=18582787&qid=144535#summary
4. 有如下类定义,下列描述错误的是? 正确答案: D
class A(object): pass class B(A): pass b = B()
A. isinstance(b, A) == True
B. isinstance(b, object) == True
C. issubclass(B, A) == True
D. issubclass(b, B) == True
解析:https://www.nowcoder.com/test/question/done?tid=18706249&qid=144536#summary
5.python my.py v1 v2 命令运行脚本,通过 from sys import argv如何获得v2的参数值? 正确答案: C
A. argv[0] B. argv[1] C. argv[2] D. argv[3]
解析:sys.argv是传递给python脚本的命令行参数【字符串】列表,argv[0]为该脚本自身路径,其余为命令行参数,所以v2应该是argv[2]
6.
bit = input("Enter a binary digit:") if bit = 0 or 1: print "your input is" ,bit else print "your input is invalid"
![](https://img2018.cnblogs.com/blog/1408256/201809/1408256-20180916212142367-1444969116.png)