程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

A collection of 40 Python interview questions sorted out by staying up late and working overtime for half a month (with answers)

編輯:Python

Python It's the most popular language in the field of programming . In this paper , I will summarize Python The most common in an interview 50 A question . Each question has a reference answer , Hope to help you in 2019 Stand out in the job interview in , Get a high paying job . These interview questions involve Python Basic knowledge of 、Python Programming 、 Data analysis and Python Function library and so on .

Q1、Python What's the difference between a list and a tuple in ?

Q2、Python What is the main function of ?

Python It's an interpretative language . And C Languages are different ,Python There is no need to compile before running .

Python It's dynamic language , When you declare a variable or something like that , You don't need to declare the type of the variable .

Python Suitable for object-oriented programming , Because it allows class definition as well as composition and inheritance .Python No access instructions ( Such as C ++ Of public,private).

stay Python in , Function is the first kind of object . They can be assigned to variables . Class is also the first kind of object

To write Python The code is fast , But it's slow .Python Allow based on C An extension of , for example numpy function library .

Python It can be used in many fields .Web Application development , automation , mathematical modeling , Big data applications and so on . It is also often used as “ glue ” Code .

Q3、Python Is it a universal programming language ?

Python Be able to write scripts , But in a general sense , It is considered to be a general programming language .

Q4、Python How to interpret language ?

Python There is no need to explain the program before it runs . therefore ,Python It's an interpretative language .

Q5、 What is? pep?

PEP representative Python Enhancement Proposal. It's a set of rules , Specify how to format Python Code for maximum readability .

Q6、 How to be in Python Manage memory in ?

python Memory management in is controlled by Python Private heap space management . all Python Objects and data structures are in the private heap . Programmers do not have access to this private heap .python The interpreter takes care of this .

Python The heap space allocation of objects is determined by Python The memory manager of . The core API Provides some tools for programmers to write code .

Python There is also a built-in garbage collector , It can reclaim all unused memory , And make it available for heap space .

Q7、Python What is the namespace in ?

A namespace is a naming system , Used to ensure that the name is unique , To avoid naming conflicts .

Q8、 What is? PYTHONPATH?

It is the environment variable used when importing the module . Whenever you import a module , You'll find it, too PYTHONPATH To check whether there are imported modules in each directory . The interpreter uses it to determine which modules to load .

Q9、 What is? python modular ?Python What are the commonly used built-in modules in ?

Python The module contains Python Code .py file . This code can be a function class or a variable . Some common built-in modules include :sys、math、random、data time、JSON.

Q10、Python What are the local and global variables in ?

Global variables : Variables declared outside a function or in global space are called global variables . These variables can be accessed by any function in the program .

local variable : Any variable declared within a function is called a local variable . This variable exists in local space , Not in global space .

Q11、python Is it case sensitive ?

yes .Python It's a case sensitive language .

Q12、 What is? Python Type conversion in ?

Type conversion is the conversion of one data type to another .

int() - Convert any data type to an integer type

float() - Convert any data type to float type

ord() - Convert characters to integers

hex() - Convert integers to hexadecimal

oct() - Convert an integer to octal

tuple() - This function is used to convert to tuples .

set() - This function is converted to set Post return type .

list() - This function is used to convert any data type to a list type .

dict() - This function is used to convert the order tuple ( key , value ) Convert to dictionary .

str() - Used to convert integers to strings .

complex(real,imag) - This function converts real numbers to complex numbers ( The set of real Numbers , Images ) Count .

Q13、 How to be in Windows Installation on Python And set the path variable ?

To be in Windows Installation on Python, Follow these steps :

from python After installing and downloading on the official website , Install it on your PC On . Use the following command at the command prompt to find PC Installation on PYTHON The location of :cmd python.

Then go to advanced system settings and add a new variable and name it PYTHON_NAME And paste the copied path .

Find the path variable , Select its value and select “ edit ”.

If the value does not exist , Please add a semicolon at the end of the value , Then type. %PYTHON_HOME%

Q14、python Whether indent is required in ?

Indentation is Python Essential . It specifies a code block . loop , class , All code in functions and so on is specified in the indent block . It's usually done with four space characters . If your code doesn't need to be indented , It will not execute accurately and will also throw errors .

Q15、Python What's the difference between arrays and lists ?

Python Arrays and lists in have the same way of storing data . however , An array can only contain a single data type element , The list can contain any data type element .

Q16、Python What is the function in ?

A function is a block of code , Only when called will it execute . To be in Python Define function in , Need to use def keyword .

Q17、 What is? __init__?

__init__ yes Python A method or structure in . Create a new class in / When an instance , This method will be called automatically to allocate memory . All classes have __init__ Method .

Q18、 What is? lambda function ?

lambda Functions are also called anonymous functions , This function can contain any number of arguments , But there can only be one statement that performs an action .

Q19、Python Medium self What is it? ?

self Is an instance or object of a class . stay Python in ,self Included in the first parameter . however ,Java This is not the case in , It's optional . It helps to distinguish between methods and properties of classes with local variables .init Methods self Variables refer to newly created objects , In other ways , It refers to the object whose method is called .

Q20、 What is? python iterator ?

Iterators are objects that can be traversed or iterated .

Q21、range&xrange What's the difference? ?

in the majority of cases ,xrange and range Exactly the same in function . They all provide a way to generate a list of integers , The only difference is range Return to one Python List objects ,x range Return to one xrange object . That means xrange In fact, the static list is not generated at runtime . It uses what's called yielding Special techniques for creating values as needed . This technique is used with an object called a generator . So if you have a very large list , Then consider xrange.

Q22、 How to be in python Write notes in ?

Python Note in to # The beginning of a character . You can also use doc-strings( String contained in triple quotes ) Annotate .

Q23、 What is? pickling and unpickling?

Pickle The module accepts any Python Object and convert it to a string representation , And use dump The function dumps it to a file , This process is called pickling. Retrieves the original string from the stored string Python The process of an object is called unpickling.

Q24、python What is the generator in ?

The function that returns an iteratable itemset is called a generator .

Q25、 How do you capitalize the first letter of a string ?

stay Python in ,capitalize() The function can capitalize the first letter of a string . If the string already contains uppercase letters at the beginning , Then it will return the original string .

Q26、 How to convert a string to all lowercase ?

To convert a string to lowercase , have access to lower() function .

Q27、 How to be in python Comment multiple lines in ?

When commenting on multiple lines of code . All lines to be annotated should be preceded by #. You can also use shortcuts to annotate multiple lines , Just press and hold trl Key and include in each # Left click on the character and type once #.

Q28、 What is? Python Documents in Docstrings?

Docstrings It's not really a comment , They are document strings . These document strings are enclosed in three quotation marks . They are not assigned to any variables , Therefore, it is sometimes used for annotation .

Q29、operators Medium is、not and in What's the function of each ?

Operators It's a special function , They compare one or more values and produce corresponding results . among is: When 2 The operands are true When to return to true( for example :“a” yes 'a')

not: Returns the reciprocal of a Boolean value

in: Check whether an element exists in a sequence

Q30、Python in help() and dir() What is the usage of the function ?

Help() and dir() Both of these functions can be derived from Python Interpreter direct access , And used to view the merge dump of built-in functions .

help() function :help() Function to display a document string , You can also view and modules , keyword , Properties and other related usage information .

dir() function :dir() Function to display the defined symbol .

Q31、 When Python Exit time , Why not clear all allocated memory ?

When Python Exit time , Especially those with circular references to other objects Python Modules or objects referenced from the global namespace are not deallocated or released .

Unable to deallocate C Those parts of memory that the library keeps .

Exit time , With its own efficient cleaning mechanism ,Python Will try to deallocate / Destroy all other objects .

Q32、Python What is the dictionary in ?

Python The built-in data type in is called a dictionary . It defines a one-to-one relationship between keys and values . The dictionary contains a pair of keys and their corresponding values . Dictionaries are indexed by keys .

Q33、 How to be in python Using the ternary operator ?

Ternary operators are operators used to display conditional statements . This includes true or false value , And must evaluate the statement for it . Its basic grammar is :

Ternary operators are operators used to display conditional statements . This includes true or false value , And must evaluate the statement for it . Its basic grammar is :

[on_true] if [expression] else [on_false] x,y = 25,50big = x if x <y else y

Q34、 Why use * args,** kwargs?

When we are not sure how many parameters to pass to the function , Or when we want to pass the stored list or parameter tuple to the function , We use * args.** Use... When we don't know how many keyword parameters to pass to the function kwargs, Or it can be used to pass the value of the dictionary as a keyword parameter . identifier args and kwargs It's an agreement , You can also use * bob and ** billy.

Q35、len() What is the function ?

len() The function can be used to determine the string , list , The length of arrays, etc .

Q36、 stay Python in split(),sub(),subn() function .

If you want to modify a string ,Python Of “re” The module provides 3 Methods . They are :

split() - Use the regular expression pattern to convert the given string “ Split ” Go to the list .

sub() - Finds all substrings that match the regular expression pattern , Then replace them with different strings

subn() - It is similar to sub(), And also returns a new string .

Q37、 What is a negative index , What is the function ?

Python The sequence in is indexed , It's made up of positive and negative numbers . Use positive numbers '0' As the first index ,'1' As the second index , The process continues to use .

The index of a negative number is from '-1' Start , Represents the last index in the sequence ,' - 2' As the penultimate index , The sequence moves forward like a positive number .

The negative index reference removes any newline from the string , And allow the string to be used as S [: - 1] The last character given . Negative indexes are also used to show that indexes represent strings in the correct order .

Q38、 What is? Python package ?

Python A package is a namespace that contains multiple modules .

Q39、 How to be in Python Delete files in ?

To be in Python Delete files in , You need to import OS modular . after , You need to use os.remove() function .

Q40、 What is? python Built in type ?

Python The built-in types in are as follows : integer 、 floating-point 、 The plural 、 character string 、 Boolean et al .

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved