Python tutorial: the most comprehensive Python110 pavement questions! Interview sure you need them!

Python tutorials (Python learning course): the most comprehensive Python face questions!

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

To everyone better digestion, to everyone out here is divided into several topics and tutorials!

 

1, the sum of a line of code to achieve 1--100

Using the sum () function sums

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

2, how to modify global variables inside a function

Internal functions global declaration modify global variables

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

3, lists five python standard library

os: provides functions related to the operating system with a lot of

sys: command-line arguments commonly used

re: regular match

math: math

datetime: date and time of treatment

4, how to merge two dictionaries and dictionaries delete key

del and update methods

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

5, under the python's GIL talk

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

6, python list of methods to achieve weight

First go through a set of heavy, in turn list

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

7, fun (* args, ** kwargs) of * args, ** kwargs What does it mean?

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

Distinction 8, python2 python3 and a range (100) of

python2 return to the list, python3 returns an iterator, save memory

9, in a word to explain what kind of language can be used decorator?

As a function of transmission parameters of the language, you can decorator

10, python built-in data types which

Integer --int

Boolean --bool

String --str

--List list

Tuple --tuple

Dictionary --dict

11, the object-oriented briefly and __init__ difference __new__

__init__ is the initialization method, after creating an object, it was immediately called by default, and can receive parameters, as

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

1、__new__至少要有一个参数cls,代表当前类,此参数在实例化时由Python解释器自动识别

2、__new__必须要有返回值,返回实例化出来的实例,这点在自己实现__new__时要特别注意,可以return父类(通过super(当前类名, cls))__new__出来的实例,或者直接是object的__new__出来的实例

3、__init__有一个参数self,就是这个__new__返回的实例,__init__在__new__的基础上可以完成一些其它初始化的动作,__init__不需要返回值

4、如果__new__创建的是当前类的实例,会自动调用__init__函数,通过return语句里面调用的__new__函数的第一个参数是cls来保证是当前类实例,如果是其他类的类名,;那么实际创建返回的就是其他类的实例,其实就不会调用当前类的__init__函数,也不会调用其他类的__init__函数。

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

12、简述with方法打开处理文件帮我我们做了什么?

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

打开文件在进行读写的时候可能会出现一些异常状况,如果按照常规的f.open

写法,我们需要try,except,finally,做异常判断,并且文件最终不管遇到什么情况,都要执行finally f.close()关闭文件,with方法帮我们实现了finally中f.close

(当然还有其他自定义功能,有兴趣可以研究with方法源码)

13、列表[1,2,3,4,5],请使用map()函数输出[1,4,9,16,25],并使用列表推导式提取出大于10的数,最终输出[16,25]

map()函数第一个参数是fun,第二个参数是一般是list,第三个参数可以写list,也可以不写,根据需求

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

14、python中生成随机整数、随机小数、0--1之间小数方法

随机整数:random.randint(a,b),生成区间内的整数

随机小数:习惯用numpy库,利用np.random.randn(5)生成5个随机小数

0-1随机小数:random.random(),括号中不传参

Python tutorial: the most comprehensive Python110 pavement questions!  There's an interview you need them

 

 

15, to avoid the escape string plus what letter represents the original string?

r, expressed the need for the original string, does not escape special characters

More Python Python tutorials and face questions will be updated in the next tutorial!

Guess you like

Origin www.cnblogs.com/cherry-tang/p/10979608.html