python interview questions - primary (a)

First, how many operators have Python?

  This type of interview questions can determine your Python skills, can cite many examples to answer such questions.

In Python we have 7 operators:

Arithmetic operators, relational (comparison) operators, assignment operators, logical operators, bit operators, members of the operators, the identity of the operator.

Detailed:

<1> arithmetic operators:

There arithmetic operators: +, -, *, /,% (remainder) // (divisible), ** (power)

 

Comparative <2> relationship, assignments, logical operators:

 

<3> Bitwise Operators

 

<4> member operator

 

 

<5> Operator Identity

Second, explain what is the difference between ==:

  is For determining whether two variables refer to the same object
  == value for determining whether the reference variable is equal to

Python three basic elements contained in the object, are: id (identity), type (data type) and value (value).

== object and is compared are determined action, but not identical, the comparison determination of content object. Here's a look at what specific differences.

== python is the standard operators in comparison operator for comparing two objects of determination value (values) are equal.
is also known as the identity operator, the operator determines that the comparison between the object unique identifier, i.e. whether the same id.

Three, python pass statement in the role:

  Placeholder placeholder main role is to make the code as a whole and complete.
  Development: Similar statements can break out of the loop.
             continue statement can skip to the next cycle.

Fourth, please explain Python closures?

 

If an internal function, the pair (but not in the global scope) were variable reference outside the scope, then the internal function is a closure .

 

V. Can you explain * args and ** kwargs?

*args 用来将参数打包成tuple给函数体调用
**kwargs 打包关键字参数成dict给函数体调用

如果我们不知道将多少个参数传递给函数,比如当我们想传递一个列表或一个元组值时,就可以使用*args。

当我们不知道将会传入多少关键字参数时,使用**kwargs 会收集关键字参数。

六、解释 Python 中的 join() 和 split() 函数

join() 函数可以将指定的字符添加到字符串中。          ‘1,2,3,4,5’

split() 函数可以用指定的字符分割字符串                    [‘1’, ‘2’, ‘3’, ‘4’, ‘5’]

七、什么是猴子补丁?

(1)运行时动态替换模块的方法
(2)运行时动态增加模块的方法

八、什么是鸭子类型?

鸭子类型关注点在对象的行为,而不是类型。在 Python 和 Go 中都可以实现鸭子类型。

定义:如果走起路来像鸭子,叫起来也像鸭子,那么它就是鸭子(If it walks like a duck and quacks like a duck, it must be a duck)

鸭子类型是编程语言中动态类型语言中的一种设计风格,一个对象的特征不是由父类决定,而是通过对象的方法决定的。

九、Python 区分大小写吗?

Python的变量名是区分大小写的,例如:name和Name就是两个变量名,而非相同变量。

变量(variable)是学习python初始时,就会接触到的一个新的知识点,也是一个需要熟知的概念。python是一种动态类型语言,在赋值的执行中可以绑定不同类型的值,这个过程叫做变量赋值操作,赋值同时确定了变量类型。

十、当退出 Python 时是否释放所有内存分配?

答案是否定的。那些具有对象循环引用或者全局命名空间引用的变量,在 Python 退出是往往不会被释放

另外不会释放 C 库保留的部分内容。

如何在python中管理内存:
Python 用一个私有堆内存空间来放置所有对象和数据结构,我们无法访问它。由解释器来管理它。不过使用一些核心 API,我们可以访问一些 Python 内存管理工具控制内存分配。

 

循序渐进,厚积薄发,量变引起质变,加油!!!2019.11.29  

 

Guess you like

Origin www.cnblogs.com/pythonbetter/p/11960254.html