[Python Study Notes]python face question

Source: Internet
Author: User
Tags floor division python script value store

1, what is pickling and unpickling? (1 points)

The Pickle module accepts any Python object, converts it to a string, and dumps it into a file using the Dump function, which is called pickling. The process of retrieving the original Python object from the stored string representation is called unpickling.

2. How does Python work as an interpreted language? (1 points)

Python is an interpreted language. The Python program runs directly from the source code, converting the programmer's source code into an intermediate language, and then translating the intermediate language into the machine language that must be executed.

3. What tools are available to help find errors or perform static analysis? (2 points)

Pychecker is a static analysis tool that detects errors in Python source code and gives the type and complexity of errors. Pylint is another tool for verifying that a module conforms to the coding standard.

4, according to the following requirements to write code to achieve the functions of: (5 points)

(1) Write code to download the contents of the Https://en.wikipedia.org/wiki/Machine_translation page and save it as mt.html

(2) Statistics mt.html <p> tags all the words and stored in the Mt_word.txt, requires:

A) each word line. Words in front, the number of occurrences of the word in the back, the Middle with tab () separated.

b) The words are arranged in numbers from many to fewer. For example, the word a appears 100 times, the word B appears 10 times, then the word a should precede the word B.

5, the following code will output what: (2 points)

def f (x,l=[]): For    I in range (x):        l.append (i*i)    print L    F (2) f (3,[3,2,1]) F (3)

Answer:

[0, 1] [3, 2, 1, 0, 1, 4] [0, 1, 0, 1, 4]

6. Read the following code, what is the output of it? (6 points)

Class Node (object): Def __init__ (self,sname): Self._lchildren = [] Self.sname = SName def __repr__ (sel f): Return "<node ' {} ' >". Format (Self.sname) def append (Self,*args,**kwargs): Self._lchildren.appen D (*args,**kwargs) def print_all_1 (self): print self for ochild in Self._lchildren:ochild.print_all_1 (            ) def print_all_2 (self): def gen. (o): LAll = [O,] while lall:onext = Lall.pop (0)                Lall.extend (Onext._lchildren) yield onext for Onode in Gen (self): print Onode                oroot = node ("root") OChild1 = node ("child1") OChild2 = node ("Child2")                oChild3 = node ("child3") OChild4 = node ("child4") OChild5 = node ("Child5") OCHILD6 = node ("Child6") OChild7 = node ("Child7") OChild8 = node ("Child8") o CHILD9 = Node ("child9")               OCHILD10 = Node ("Child10") oroot.append (oChild1) oroot.append (oChild2)                Oroot.append (oChild3) ochild1.append (oChild4) ochild1.append (OCHILD5) Ochild2.append (OCHILD6) ochild4.append (OCHILD7) ochild3.append (OCHILD8) oCh Ild3.append (OCHILD9) Ochild6.append (OCHILD10) # describes the output of the following code Oroot.print_all_1 () oroot.print_all_2 ()

Answer

7. What does lambda mean in python? (1 points)

It is a single-expression anonymous function that is often used as an inline function.

8. Why does the lambda form in Python have no statements? (1 points)

The lambda form in Python does not have a statement because it is used to create new function objects and then return them at run time.

9. What does the pass in Python mean? (1 points)

Pass means that there is no operational Python statement, in other words, it is a placeholder in a compound statement, and if there is nothing in a place that must be written there, you need to use the pass.

10. Read the code below and write the final value of A0,A1 to an. (5 points)

A0 = dict (Zip (' A ', ' B ', ' C ', ' d ', ' E '), (1,2,3,4,5))) A1 = Range (Ten) A2 = [i-I in A1 if i in a0]a3 = [A0[s] for s in a0]a4 = [I for I in A1 if I in A3] A5 = {I:i*i for i in a1}a6 = [[I,i*i] for i in A1]

11. What is the unit test for Python? (1 points)

The unit test framework in Python is called UnitTest. It supports shared settings, automated testing, test shutdown code, test sets, and more.

12. What is unittest in Python? (1 points)

The mechanism for selecting a series of items from a list, tuple, string, and other sequence types is called UnitTest.

13. What is a generator in python? (1 points)

The way the iterator is implemented is called the generator. In addition to generating an expression in a function, it is a normal function.

14. Difference between __new__ and __init__ (4 points)

15. How do I copy the objects in Python? (2 points)

To copy an object in Python, you can generally try Copy.copy () or copy.deepcopy (). You cannot copy all of the objects, but most of them are still possible.

16. How do I convert a number to a string? (2 points)

To convert a number to a string, use the built-in function str (). If you want an octal or hexadecimal representation, use the built-in function Oct () or Hex ().

17. What is the difference between xrange and range? (2 points)

Xrange returns an Xrange object, and range returns an array. Use the same memory regardless of the range.

18. What are the modules and packages in Python? (3 points)

In Python, a module is a way to construct a program. Each Python program file is a module that imports other modules, such as objects and properties.

The folder for the Python program is a module package, which can have modules or sub-folders.

19. What are the rules that refer to local and global variables in python? (3 points)

Local variables: If a variable is assigned a new value anywhere within the body of the function, it is considered local.

Global variables: Variables defined with global variables

When the local variable name and the global variable name are repeated, the local variable overrides the global variable.

20. How can I share global variables across modules? (3 points)

To share global variables between modules in a single program, create a configuration module. Import the configuration module in all modules of the application, which will be provided as a global variable across modules.

21. Explains how to create a Python script executable file on Unix? (4 points)

There are two things you need to do to create a Python script executable on Unix:

· The schema of the script file must be executable

· The first line must be # (#! /Usr/local/bin/python) Start

22. Python garbage collection mechanism (3 points)

Python GC uses reference counts (reference counting) primarily to track and recycle garbage. On the basis of reference counting, through "mark-clear" (Mark and sweep) to solve the problem that the container object may produce circular reference, through "generational recovery" (generation collection) to improve garbage collection efficiency by means of space-time-changing.

23. Explain how to generate random numbers in Python? (3 points)

To generate a random number in Python, you need to import the command

Random import: Random.random ()

This returns the random floating-point number in the range [0,1]

24. Explain how to access Python modules written in C language? (3 points)

You can use the following method to access a module written in C,

Module = = Pyimport_importmodule ("<modulename>");

25. How do I use the//operator in Python? (1 points)

It is a floor division Operator that divides the two operands and results in the number preceding the decimal point. For example, 10//5 = 2 and 10.0//5.0 = 2.0.

26. Mention the five benefits of using Python? (2 points)

· Python contains a huge library of standards for most internet platforms, such as e-mail, HTML, and so on.

· Python does not require explicit memory management because the interpreter itself allocates memory to new variables and automatically frees them

· Readability due to the use of square brackets

· Easy for Beginners to learn

  · With built-in data types, you can save programming time and effort to declare variables.

27. How do I use the split function in Python? (1 points)

Using the Split function in Python is to break the string into shorter strings using a defined delimiter. It gives a list of all the words in the string.

28, explain what is flask and its benefits? (2 points)

Flask is a web mini-framework based on the "Werkzeug,jinja 2 and good intentions" BSD license, and Werkzeug and Jingja are its two dependencies.

Flask is part of the micro-framework. This means that it will have little or no reliance on external libraries, which makes the framework a breeze, with fewer updates and security breaches.

29. What is the difference between django,pyramid and flask? (3 points)

Flask is a "micro-framework" that is used primarily for small applications with simpler requirements. In flask, you must use an external library.

The pyramid is built for larger applications. It provides flexibility and allows developers to use the right tools for their projects. Developers can choose databases, URL structures, template styles, and so on.

Pyramid can be reconfigured. Like Pyramid, Django can also be used for larger applications. It includes an ORM.

30. What is FLASK-WTF and what are the characteristics? (3 points)

FLASK-WTF provides simple integration with Wtforms, features include:

· Integration with Wtforms

· Use CSRF token security Form

· Global CSRF Protection

· Reptcha Support

    · File uploads for use with flask uploads

31. What are the common ways of flask scripts? (1 points)

should be the path to the application's import path or Python file

32. How to access the session in flask? (2 points)

A session basically allows to remember information from one request to another request. In flask, it uses a signed cookie so that the user can view the contents of the session and make modifications. The user can modify the session as long as it has a key flask.secret_key.

33. Is flask an MVC model? If so, can you show me a sample? (5 points)

Basically, flask is a simple framework that behaves the same as the MVC framework. So MVC is the perfect choice for flask, examples are as follows:

34. Explain the database connection in Python flask? (5 points)

Flask supports database-driven applications (RDBS). Such a system would need to create a schema to transfer the Shema.sql file to the Sqlite3 command. Therefore, the Sqlite3 command is required to create or start the database in flask.

Flask allows the database to be requested in three different ways

· Before_request (): they are called before the request and do not pass any parameters

· After_request (): They are called after the request and delivery will be sent to the client response

· Teardown_request (): Called when an exception is thrown, and does not guarantee a response. They are called after the response is finished. They are not allowed to modify requests, their values are ignored.

35, you have more than one memcache server running Python, one of the Memcacher server failed, it has your data, it will try to get the critical data from the failed server? (5 points)

The data in the failed server is not deleted, but automatic failure rules can be configured for multiple nodes. You can trigger a failover during any type of socket or memcached server-level error without triggering a normal client error, such as adding an existing key.

36. Explain how to minimize memcached server outages in Python development? (5 points)

When an instance fails, this will reload the lost data when the client makes a request and bear a greater load on the database server. To avoid this situation, if the code has been written to minimize the impact of the cache, then it will have minimal impact

Another method is to start the memcached instance on the new machine using the Lost machine IP address

Code is another way to minimize server downtime because it is free to change the memcached server list with minimal effort

Setting the time-out value is another option for some memcached clients to implement for Memcached server interrupts. When the memcached server shuts down, the client will continue to attempt to send the request until the timeout limit is reached

37. Memcached should not be used in the explanation Python project? (5 points)

Memcached Common misuse is to use it as a data store, rather than as a cache

Never use memcached as the only source of information needed to run your application, and data should always be available from other sources

Memcached is just a key or value store, cannot perform queries on data or traverse content to extract information

Memcached does not provide any form of security when encrypting or authenticating

[Python Study Notes]python face question

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.