保存成功
保存失败,请重试
提交成功
编程语言
Python 面试题系列 200 道:2019 版
<div class="output_wrapper" id="output_wrapper_id" style="font-size: 15px; color: rgb(0, 0, 0); line-height: 1.5; word-spacing: 1px; letter-spacing: 1px; font-family: 'Microsoft YaHei'; background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%); background-size: 20px 20px; background-position: center center;"><h3 id="h" style="color: inherit; line-height: inherit; padding: 0px; margin: 1em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">引言</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0.5em 0px;">最近在刷面试题,所以需要看大量的 Python 相关的面试题,从大量的题目中总结了很多的知识,同时也对一些题目进行拓展了,但是在看了网上的大部分面试题不是很满意,一个是有些部分还是 Python2 的代码,另一个就是回答的很简单,有些关键的题目,也没有点出为什么,最重要的是还有一些复制粘贴根本就跑不通,这种相信大家深有体会吧,这样就导致我们可能需要去找其他人发的类似的教程。难受啊,所以我决定针对市面上大多的 Python 题目做一个分析,同时也希望大家尽可能的做到举一反三,而不是局限于题目本身。大概就这样吧,有你看过的题目也有你没看到过的。</p> <h3 id="hchat" style="color: inherit; line-height: inherit; padding: 0px; margin: 1em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">通过本场 Chat,你将获得如下知识点:</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;"> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">掌握 Python 的基础语法</span></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">语法常见的 Python 应用场景</span></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">掌握Python闭包的使用以及装饰器的使用</span></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">生成器和迭代器的使用</span></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">常见的设计模式的使用</span></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">深浅拷贝的区别</span></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">线程、进程、协程的使用</span></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">了解 Python 中的元编程和反射</span></li> </ul> <h3 id="h-1" style="color: inherit; line-height: inherit; padding: 0px; margin: 1em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">部分题目</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0.5em 0px;">1.解释一下python中pass语句的作用?<br>2.简述你对input()函数的理解<br>3.已知AList = [1,2,3,1,2],对AList列表元素去重,写出具体过程。<br>4.Python交换两个变量的值<br>5.在读文件操作的时候会使用read、readline或者readlines,简述它们各自的左右<br>6.python中的is和==<br>7.Python中的作用域<br>8.函数装饰器有什么作用?请列举说明?<br>9.谈谈对Python和其他语言的区别<br>10.简述解释型和编译型编程语言<br>11.如何反转字符串"hello world"?<br>12.Python的解释器种类以及相关特点?<br>13.三元运算写法和应用场景?<br>14.Python3和Python2的区别?<br>15.Python3和Python2中int和long区别?<br>16.xrange和range的区别?<br>17.了解enumerate么?<br>18.Python垃圾回收机制?<br>19.列举5个Python中的标准模块<br>20.如何实现 "1,2,3" 变成 ["1","2","3"]<br>21.如何在函数中设置一个全局变量<br>22.Python中的字符串格式化方式你知道哪些?<br>23.用Python实现一个二分查找的函数<br>24.魔法函数 __call__怎么使用?<br>25.如何判断一个对象是函数还是方法?<br>26.pathlib的用法举例<br>27.@classmethod和@staticmethod用法和区别<br>28.Python 中的接口如何实现?<br>29.Python中的反射了解么?<br>30.metaclass作用?以及应用场景?<br>31.Python中的异常处理,写一个简单的应用场景<br>32.Python中递归的最大次数,那如何突破呢?<br>33.什么是面向对象的mro<br>34.isinstance作用以及应用场景?<br>35.json序列化时,可以处理的数据类型有哪些?如何定制支持datetime类型?<br>36.json序列化时,默认遇到中文会转换成unicode,如果想要保留中文怎么办?<br>37.什么是断言?应用场景?<br>38.lambda表达式格式以及应用场景?<br>39.python单例模式的实现方法<br>40.使用Python实现一个斐波那契数列<br>41.新式类和旧式类的区别<br>42.hasattr() getattr() setattr()的用法<br>43.dir()是干什么用的?<br>44.给定两个list,A和B,找出相同元素和不同元素<br>45.有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),输出到一个新文件C中。<br>46.有一个字符串开头和末尾都有空格,比如“ adabdw ”,要求写一个函数把这个字符串的前后空格都去掉。<br>47.如果当前的日期为20190530,要求写一个函数输出N天后的日期,(比如N为2,则输出20190601)。<br>48.下面这段代码输出什么?</p> <pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><code class="hljs python" style="overflow-wrap: break-word; margin: 0px 2px; line-height: 18px; font-size: 14px; font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); overflow-x: auto; padding: 0.5em; display: block !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important;">num&nbsp;=&nbsp;<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">9</span><br><br><span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">def</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">f1</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">()</span>:</span><br>&nbsp;&nbsp;&nbsp;&nbsp;num&nbsp;=&nbsp;<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">20</span><br><br><span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">def</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">f2</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">()</span>:</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">print</span>&nbsp;num<br><br>f2()<br>f1()<br>f2()<br></code></pre> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0.5em 0px;">49.写一个函数,接收整数参数n,返回一个函数,函数的功能是把函数的参数和n相乘并把结果返回。<br>50.一个包里有三个模块,demo1.py, demo2.py, demo3.py,但使用from tools import *导入模块时,如何保证只有demo1、demo3被导入了。<br>51.下面代码会存在什么问题,如何改进?</p> <pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><code class="hljs python" style="overflow-wrap: break-word; margin: 0px 2px; line-height: 18px; font-size: 14px; font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); overflow-x: auto; padding: 0.5em; display: block !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important;"><span class="hljs-function" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">def</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">strappend</span><span class="hljs-params" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(255, 152, 35); word-wrap: inherit !important; word-break: inherit !important;">(num)</span>:</span><br>&nbsp;&nbsp;&nbsp;&nbsp;str=<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">'first'</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">for</span>&nbsp;i&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">in</span>&nbsp;range(num):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str+=str(i)<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">return</span>&nbsp;str<br></code></pre> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0.5em 0px;">52.Python常用的数据结构的类型及其特性?</p> <pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><code class="hljs makefile" style="overflow-wrap: break-word; margin: 0px 2px; line-height: 18px; font-size: 14px; font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); overflow-x: auto; padding: 0.5em; display: block !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important;"><span class="hljs-section" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">A:{1:0,2:0,3:0}</span><br><span class="hljs-section" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">B:{"a":0,&nbsp;"b":0,&nbsp;"c":0}</span><br><span class="hljs-section" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">C:&nbsp;{(1,2):0,&nbsp;(2,3):0}</span><br><span class="hljs-section" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">D:&nbsp;{[1,2]:0,&nbsp;[2,3]:0}</span><br></code></pre> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0.5em 0px;">53.已知:</p> <pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><code class="hljs ini" style="overflow-wrap: break-word; margin: 0px 2px; line-height: 18px; font-size: 14px; font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); overflow-x: auto; padding: 0.5em; display: block !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important;"><span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">AList</span>&nbsp;=&nbsp;[<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">1</span>,<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">2</span>,<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">3</span>]<br><span class="hljs-attr" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(165, 218, 45); word-wrap: inherit !important; word-break: inherit !important;">BSet</span>&nbsp;=&nbsp;{<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">1</span>,<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">2</span>,<span class="hljs-number" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">3</span>}<br></code></pre> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0.5em 0px;">(1) 从AList 和 BSet中 查找 4,最坏时间复杂度那个大?<br>(2) 从AList 和 BSet中 插入 4,最坏时间复杂度那个大?<br>54.获取字符串”123456“最后的两个字符。<br>55.请列举你知道的Python的魔法方法及用途。<br>56.列举5个Python中的异常类型以及其含义<br>57.copy和deepcopy的区别是什么?<br>58.如何将元组("A","B")和元组(1,2),合并成字典{"A":1,"B":2}<br>59.代码中经常遇到的*args, **kwargs含义及用法。<br>60.一行代码输出1-100之间的所有偶数。<br>61.Python里面如何实现tuple和list的转换?<br>62.如何知道一个Python对象的类型?<br>63.Python的传参是传值还是传址?<br>64.with语句的作用,写一段代码?<br>65.一个编码为 GBK 的字符串 S,要将其转成UTF-8编码的字符串,应如何操作?<br>66.在requests模块中,requests.content和requests.text什么区别<br>67.Python中会有函数或成员变量包含单下划线前缀和结尾,和双下划线前缀结尾,区别是什么?<br>68.单引号、双引号、三引号的区别?<br>69.Python中的元类(metaclass)使用举例<br>70.我们知道对于列表可以使用切片操作进行部分元素的选择,那么如何对生成器类型的对象实现相同的功能呢?<br>71.使用正则表达式匹配出&lt;html&gt;&lt;h1&gt;www.baidu.com&lt;/html&gt;中的地址<br>72.w、a+、wb文件写入模式的区别<br>73.python字典和json字符串相互转化方法<br>74.s="info:xiaoZhang 33 shandong",用正则切分字符串输出['info', 'xiaoZhang', '33', 'shandong']<br>74.举例sort和sorted的区别<br>75.a = "你好 中国 ",去除多余空格只留一个空格。<br>76.请将[i for i in range(3)]改成生成器<br>77.简述any()和all()方法<br>78.字典操作中del和pop有什么区别<br>79.list=[2,3,5,4,9,6],从小到大排序,不许用sort,输出[2,3,4,5,6,9]<br>80.a="hello"和b="你好"编码成bytes类型<br>81.a="张明 98分",用re.sub,将98替换为100<br>82.[[1,2],[3,4],[5,6]]一行代码展开该列表,得出[1,2,3,4,5,6]<br>83.正则表达式匹配中(.*)和(.*?)匹配区别?<br>84.合并列表[1,5,7,9]和[2,2,6,8]<br>85.filter方法求出列表所有奇数并构造新列表,a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]<br>86.什么是猴子补丁?<br>87.请写一个 Python 逻辑,计算一个文件中的大写字母数量<br>88.什么是负索引?<br>89.如何打乱一个列表的元素?<br>90.怎样将字符串转换为小写?<br>91.pprint模块是干什么的?<br>92.简要写一下lxml模块的使用方法框架<br>93.解释一下 Python 中的赋值运算符<br>94.解释一下 Python 中的逻辑运算符<br>95.讲讲 Python 中的位运算符<br>96.在 Python 中如何使用多进制数字?<br>97.怎样声明多个变量并赋值?<br>98.举例说明conccurent.future的中线程池的用法<br>99.在Python中是如何管理内存的?<br>100.当退出 Python 时是否释放所有内存分配?</p></div>
陈祥安 · 高级爬虫工程师
活动已取消
点击查看更多
相关专题
订阅提示×
关扫码关注公众号,和「编程语言」前沿新知互联!
微信扫描登录