Python笔试面试题_牛客(待完善)

中文,免费,零起点,完整示例,基于最新的Python 3版本。https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000

一、选择题

1. Python中单下划线_foo与双下划线__foo与__foo__的成员,下列说法正确的是? A B C

A._foo 不能直接用于’from module import *’
B. __foo解析器用_classname__foo来代替这个名字,以区别和其他类相同的命名
C. __foo__代表python里特殊方法专用的标识

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))

解析:

 二、代码小题

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

 装饰器:https://www.zhihu.com/question/26930016/answer/99243411
     https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014318435599930270c0381a3b44db991cd6d858064ac0000
函数的参数:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431752945034eb82ac80a3e64b9bb4929b16eeed1eb9000

 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"
以上程序要求用户输入二进制数字0/1并显示之,请指出程序中代码第几行存在错误:正确答案:A D
A. 4  B. 5  C. 3  D. 2
解析:

三、程序大题

长得丑就应该多读书。我爱学习,只爱学习,最爱学习!
原文地址:https://www.cnblogs.com/xc-718/p/9637302.html