python face questions one week summary: Friday

89, two ways to space

 

90, the regular match does not end 4 and 7 mobile phone number

 

91, brief reference counting mechanism python

python reference counting garbage collector mainly based, mark - sweep and clear the mechanism, supplemented by a generational, wherein the mark - sweep and generational recovery primarily to address the problem of circular references.

When a variable holds a reference to an object, the object's reference count is increased by one

When del delete an object variable points, if the object's reference count is not 1, such as 3, then the time will only make the reference count by 1, that is, to 2, when calling del again, to 1, if once again calls del, this time will really put the deleted objects

Reference counting algorithm

When a variable holds a reference to an object, the object's reference count is increased by one

When del delete an object variable points, if the object's reference count is not 1, such as 3, then the time will only make the reference count by 1, that is, to 2, when calling del again, to 1, if once again calls del, this time will really put the deleted objects

 

92, int ( "1.4"), int (1.4) output?

int ( "1.4") error, int (1.4) Output 1

 

93, the above mentioned three coding specification PEP8

1, the top is defined between the two blank spaces, such as functions or class definitions.

2, between the method definition, a class definition and the first method, a blank line should

3, triple quotes annotation

4, Pycharm, Eclipse generally use four spaces to indent your code

 

94, the regular expression match the first URL

findAll () method without adding the results of group ()

search () method need to add group () Extraction

95, the regular match Chinese

 

96, briefly optimistic and pessimistic locking

Pessimistic locking , is very pessimistic, pick up data every time the thought that others will modify, so every time she took the data will be locked, so people want to take this data will block until it got the lock. Traditional relational database inside to use a lot of this locking mechanism, such as row locks, table locks, etc., read lock, write lock, are locked before doing the first operation.

Optimistic locking is very optimistic, pick up data every time that others are not modified, so it will not be locked, but when the update will determine what others during this time did not go to update the data, you can use the version number and other mechanisms, optimistic locking is suitable for the types of applications to read, which can improve throughput

 

97, r, r +, rb, rb + file is opened by mode

98, Linux command to redirect> and >>

 

Linux 允许将命令执行结果 重定向到一个 文件

将本应显示在终端上的内容 输出/追加 到指定文件中

> 表示输出,会覆盖文件原有的内容

>> 表示追加,会将内容追加到已有文件的末尾

用法示例:

将 echo 输出的信息保存到 1.txt 里echo Hello Python > 1.txt
将 tree 输出的信息追加到 1.txt 文件的末尾tree >> 1.txt

 

99、正则表达式匹配出<html><h1>www.itcast.cn</h1></html>

前面的<>和后面的<>是对应的,方法如下:

 

100、python传参数是传值还是传址?

Python中函数参数是引用传递(注意不是值传递)。对于不可变类型(数值型、字符串、元组),因变量不能修改,所以运算不会影响到变量自身;而对于可变类型(列表字典)来说,函数体运算可能会更改传入的参数变量。

 

101、求两个列表的交集、差集、并集

 

102、生成0-100的随机数

random.random()生成0-1之间的随机小数,所以乘以100得到0-100的随机小数

random.choice() 随机选择range()范围内的数

random.randint() 得到0-100的随机整数

 

103、lambda匿名函数好处

精简代码,lambda省去了定义函数,map省去了写for循环过程

 

104、常见的网络传输协议

UDP、TCP、HTTP、DNS、SMTP、POP3、ICMP、IP、ARP等等

 

105、单引号、双引号、三引号用法

1、单引号和双引号没有什么区别,不过单引号不用按shift,打字稍微快一点。表示字符串的时候,单引号里面可以用双引号,而不用转义字符,反之亦然。

'She said:"Yes." ' or  "She said: 'Yes.' "

 

2、但是如果直接用单引号扩住单引号,则需要转义,像这样:

 ' She said:\'Yes.\' '

 

3、三引号可以直接书写多行,通常用于大段,大篇幅的字符串

"""

hello

world

"""

 

106、python垃圾回收机制

python垃圾回收主要以引用计数为主,标记-清除和分代清除为辅的机制,其中标记-清除和分代回收主要是为了处理循环引用的难题。

 

107、HTTP请求中get和post区别

下面的表格比较了两种 HTTP请求方法:GET 和 POST。

  GET POST
后退按钮/刷新 无害 数据会被重新提交(浏览器应该告知用户数据会被重新提交)。
书签 可收藏为书签 不可收藏为书签
缓存 能被缓存 不能缓存
编码类型 application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data。为二进制数据使用多重编码。
历史 参数保留在浏览器历史中。 参数不会保存在浏览器历史中。
对数据长度的限制 是的。当发送数据时,GET 方法向 URL 添加数据;URL 的长度是受限制的(URL 的最大长度是 2048 个字符)。 无限制。
对数据类型的限制 只允许 ASCII 字符。 没有限制。也允许二进制数据。
安全性 与 POST 相比,GET 的安全性较差,因为所发送的数据是 URL 的一部分。

在发送密码或其他敏感信息时绝不要使用 GET !
POST 比 GET 更安全,因为参数不会被保存在浏览器历史或 web 服务器日志中。
可见性 数据在 URL 中对所有人都是可见的。 数据不会显示在 URL 中。
数据传递               Get 将数据按照 “变量=值”的形式,添加到URL 后面,并且两者使用“?”连接,而各个变量之间使用“&”连接;  Post 是将数据按照变量和值相对应的方式,放到数据体中,传递给所指向的 URL。

 

107、python中读取Excel文件的方法

应用数据分析库pandas

 

108、python正则中search和match

Guess you like

Origin blog.csdn.net/qq_42415326/article/details/93876591