python interview must see (1)

1. On the python's GIL under

GIL Global is the python interpreter lock, the same process if there are multiple threads running, a thread when running python program will occupy the python interpreter (ie had a lock GIL), the other threads within that process can not run, and so the thread running after other threads to run.

If the process thread running encountered time-consuming operation, the interpreter unlock the lock, so that other threads to run. So in multiple threads, the thread is still running is a sequential, not simultaneous. Run multiple processes at the same time in each process can be allocated as system resources, equivalent to each process has a python interpreter, it can achieve multi-process multiple processes, the big disadvantage is that the process of system resource overhead

(2. Fun args, ** kwargs) in args, ** kwargs What does it mean?

Here Insert Picture Description
Here Insert Picture Description

3.10 Linux common commands

ls  pwd  cd  touch  rm  mkdir  tree  cp  mv  cat  more  grep  echo

4. database query optimization methods

Foreign keys, indexes, union query, select specific fields, etc.

5. How encountered bug treatment

1, the details of the error, () Print Print, can be performed to a print () described above code generally no problem, if the detection program segment in question, if it can alert or js console.log

2, if it involves a number of third-party frameworks, go check the official documentation or technical blog.

3, for bug management and classified summary of the general test will test out the bug with teambin bug management tools such as record, then we will make changes one by one, the process is modified to improve their understanding of the business logic and programming logic of careful method, I will make some notes record collection.

Question 4 error, guided package problem, city location polyphone caused

6. The properties are set forth to optimize web project from the front end, a rear end, the database

There are many ways that topic online, I do not want a long string of text screenshot online, look headache, according to my own understanding to say a few
front-end optimization :

1, to reduce the http request, for example made sprite 2, on the top of the page and CSS html, javascript on the following pages, as HTML js loading and loading slower than Css, so to load the priority html and css, to prevent incomplete page display, poor performance, but also affects poor user experience

后端优化

1、缓存存储读写次数高,变化少的数据,比如网站首页的信息、商品的信息等。应用程序读取数据时,一般是先从缓存中读取,如果读取不到或数据已失效,再访问磁盘数据库,并将数据再次写入缓存。
2、异步方式,如果有耗时操作,可以采用异步,比如celery
3、代码优化,避免循环和判断次数太多,如果多个if else判断,优先判断最有可能先发生的情况

数据库优化

1、如有条件,数据可以存放于redis,读取速度快
2、建立索引、外键等

7. 列出常见MYSQL数据存储引擎

InnoDB:支持事务处理,支持外键,支持崩溃修复能力和并发控制。如果需要对事务的完整性要求比较高(比如银行),要求实现并发控制(比如售票),那选择InnoDB有很大的优势。如果需要频繁的更新、删除操作的数据库,也可以选择InnoDB,因为支持事务的提交(commit)和回滚(rollback)。

MyISAM:插入数据快,空间和内存使用比较低。如果表主要是用于插入新记录和读出记录,那么选择MyISAM能实现处理高效率。如果应用的完整性、并发性要求比 较低,也可以使用。

MEMORY:所有的数据都在内存中,数据的处理速度快,但是安全性不高。如果需要很快的读写速度,对数据的安全性要求较低,可以选择MEMOEY。它对表的大小有要求,不能建立太大的表。所以,这类数据库只使用在相对较小的数据库表。

8. 简述cookie和session的区别

1,session 在服务器端,cookie 在客户端(浏览器).

2、session 的运行依赖 session id,而 session id 是存在 cookie 中的,也就是说,如果浏览器禁用了 cookie ,同时 session 也会失效,存储Session时,键与Cookie中的sessionid相同,值是开发人员设置的键值对信息,进行了base64编码,过期时间由开发人员设置.

3、cookie安全性比session差

9. 简述多线程、多进程

进程
1、操作系统进行资源分配和调度的基本单位,多个进程之间相互独立

2、稳定性好,如果一个进程崩溃,不影响其他进程,但是进程消耗资源大,开启的进程数量有限制

线程:
1、CPU进行资源分配和调度的基本单位,线程是进程的一部分,是比进程更小的能独立运行的基本单位,一个进程下的多个线程可以共享该进程的所有资源

2、如果IO操作密集,则可以多线程运行效率高,缺点是如果一个线程崩溃,都会造成进程的崩溃

应用:
IO密集的用多线程,在用户输入,sleep 时候,可以切换到其他线程执行,减少等待的时间

CPU密集的用多进程,因为假如IO操作少,用多线程的话,因为线程共享一个全局解释器锁,当前运行的线程会霸占GIL,其他线程没有GIL,就不能充分利用多核CPU的优势

10. python中copy和deepcopy区别

1、复制不可变数据类型,不管copy还是deepcopy,都是同一个地址当浅复制的值是不可变对象(数值,字符串,元组)时和=“赋值”的情况一样,对象的id值与浅复制原来的值相同。
Here Insert Picture Description
2、复制的值是可变对象(列表和字典)

浅拷贝copy有两种情况:

第一种情况:复制的 对象中无 复杂 子对象,原来值的改变并不会影响浅复制的值,同时浅复制的值改变也并不会影响原来的值。原来值的id值与浅复制原来的值不同。

第二种情况:复制的对象中有 复杂 子对象 (例如列表中的一个子元素是一个列表), 改变原来的值 中的复杂子对象的值 ,会影响浅复制的值。

深拷贝deepcopy:完全复制独立,包括内层列表和字典

11. 列出几种魔法方法并简要介绍用途

init:对象初始化方法

new:创建对象时候执行的方法,单列模式会用到

str:当使用print输出对象的时候,只要自己定义了

str(self)方法,那么就会打印从在这个方法中return的数据

del:删除对象执行的方法

12. python垃圾回收机制

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

引用计数算法当有1个变量保存了对象的引用时,此对象的引用计数就会加1

当使用del删除变量指向的对象时,如果对象的引用计数不为1,比如3,那么此时只会让这个引用计数减1,即变为2,当再次调用del时,变为1,如果再调用1次del,此时会真的把对象进行删除

13. 简述乐观锁和悲观锁

悲观锁, 就是很悲观,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这个数据就会block直到它拿到锁。传统的关系型数据库里边就用到了很多这种锁机制,比如行锁,表锁等,读锁,写锁等,都是在做操作之前先上锁。

乐观锁,就是很乐观,每次去拿数据的时候都认为别人不会修改,所以不会上锁,但是在更新的时候会判断一下在此期间别人有没有去更新这个数据,可以使用版本号等机制,乐观锁适用于多读的应用类型,这样可以提高吞吐量。

14. HTTP请求中get和post区别

1、GET请求是通过URL直接请求数据,数据信息可以在URL中直接看到,比如浏览器访问;而POST请求是放在请求头中的,我们是无法直接看到的;

2、GET提交有数据大小的限制,一般是不超过1024个字节,而这种说法也不完全准确,HTTP协议并没有设定URL字节长度的上限,而是浏览器做了些处理,所以长度依据浏览器的不同有所不同;POST请求在HTTP协议中也没有做说明,一般来说是没有设置限制的,但是实际上浏览器也有默认值。总体来说,少量的数据使用GET,大量的数据使用POST。

3、GET请求因为数据参数是暴露在URL中的,所以安全性比较低,比如密码是不能暴露的,就不能使用GET请求;POST请求中,请求参数信息是放在请求头的,所以安全性较高,可以使用。在实际中,涉及到登录操作的时候,尽量使用HTTPS请求,安全性更好。

15. python设计模式

  1. 单例模式(Singleton pattern)
    确保一个类只有一个实例, 并提供全局访问点。
    示例:
class S:
    instance = None
    
    def __new__(cls, *args, **kwargs):
        if S.instance is None:
            S.instance = super().__new__(cls)
    def __init__(self):
        pass
s1 = S()
print(id(s1))
s2 = S()
print(id(s2)
  1. 多例模式(Multition pattern)
    在一个解决方案中结合两个或多个模式, 以解决一般或重复发生的问题.。

  2. 工厂模式(factory method pattern)
    定义了一个创建对象的接口, 但由子类决定要实例化的类是哪一个。工厂方法让类把实例化推迟到子类。

  3. 原型模式(prototype pattern)
    当创建给定类的实例过程很昂贵或很复杂时, 就使用原形模式。

  4. 抽象工厂模式(Abstract factory pattern)
    提供一个接口, 用于创建相关或依赖对象的家族, 而不需要指定具体类。

  5. Generating mode (Builder pattern)
    using the pattern generator configured to process a product package, and allows configuration step by step. It represents the construct and its separation of a complex object, such that the same build process can create different representations.

16. Talk about the difference between HTTP and HTTPS?

HTTP data transmission protocol is unencrypted, plain text is therefore transmitted using the HTTP protocol is insecure private information, in order to ensure the privacy of data transmission can be encrypted, so the design Netscape SSL (Secure Sockets Layer) protocol for HTTP protocol for data transmission is encrypted, and thus was born HTTPS.

In simple terms, HTTPS protocol is constructed from SSL + HTTP protocol can be encrypted transmission, network authentication protocol than http protocol security.

The main difference between HTTPS and HTTP as follows:

1, https protocol ca need to apply for a certificate, generally less free certificates, thus requiring a fee.
2, http is the hypertext transfer protocol, information is transmitted in the clear, https is encrypted with a security ssl transfer protocol.
3, http and https use is completely different connections, with the port are not the same, the former is 80, which is 443.
4, http connection is very simple, is stateless; is constructed by the HTTPS protocol SSL + HTTP encrypted transmission protocol, a network authentication protocol, the http protocol than security.

Released nine original articles · won praise 1 · views 451

Guess you like

Origin blog.csdn.net/qq_45785397/article/details/104317296