Python engineer face questions related to Python basic syntax

Source: Internet
Author: User
I hope this article can help you through the Python interview, and then there is a Python web-related article to welcome everyone to read.

1. What is the function of the pass statement in Python?
Pass statement does nothing, generally as a placeholder or create a placeholder, the pass statement will not do anything.

2. How does Python perform type conversions?
Python provides built-in functions that convert a variable or value from one type to another type. An int function, for example, can convert a numeric string that conforms to a mathematical format into an integer. Otherwise, an error message is returned.

3. How does python perform memory management?
Python refers to a memory pool mechanism, the pymalloc mechanism (malloc:n. Allocate memory), which manages the application and deallocation of small chunks of memory.

4, dict the items () method differs from the Iteritems () method? The
Items method returns all dictionaries in a list, where the items are returned without a special order; The
Iteritems method has a similar effect, but returns an iterator object
5, what is a lambda function? What good is it? The lambda expression mentioned in
programming is usually used in situations where a function is required but does not bother to name a function, that is, an anonymous function.
Python allows you to define a small single-line function. The form of a lambda function is defined as follows: Labmda parameter: The expression lambda function returns the value of the expression by default. You can also assign it to a variable. A lambda function can accept any parameter, including optional arguments, but only one expression.
6, the Description Os,sys module is different, and enumerates common module method?
official explanation:
Os:this module provides a portable the Usingoperating system dependent functionality.
Translation: Provides a convenient way to use operating system functions.
Sys:this module provides access to some variablesused or maintained by the interpreter and to functions that interact Stronglywith the interpreter.
Translation: Provides access to variables used or maintained by the interpreter and functions used in interaction with the interpreter.
Common OS methods

SYS Common Methods

SYS.ARGV command line argument list, the first element is the program itself path Sys.modules.keys () returns all imported Modules list Sys.exc_info () Gets the exception class currently being processed, Exc_type, Exc_value, E Xc_traceback the exception details currently handled Sys.exit (n) exit the program, exit normally (0) Sys.hexversion get the version value of the Python interpreter, 16 binary format such as: 0x020403f0 Sys.versi   On gets the version information of the Python interpreter sys.maxint the largest int value sys.maxunicode the largest Unicode value Sys.modules returns the system-imported module field, key is the module name, and value is the module Sys.path returns the search path to the module, initializes with the value of the PYTHONPATH environment variable Sys.platform returns the operating system platform name Sys.stdout standard output Sys.stdin standard input SYS.S Tderr Error Output Sys.exc_clear () is used to clear the current or most recent error message that occurs on the current thread Sys.exec_prefix returns the location of the platform standalone Python file installation Sys.byteorder local byte rule indicator, B The value of the Ig-endian platform is ' big ', the value of Little-endian platform is ' little ' sys.copyright record python copyright related things sys.api_version interpreter C API version Sys.version_info sys.argv command line argument list, the first element is the program itself path Sys.modules.keys () returns all imported Modules list Sys.exc_info () Gets the exception class currently being processed, ex C_type, Exc_value, Exc_traceback exception details currently handled Sys.exit (n) exiting the program, exit Normal exit (0) Sys.hexversion get the version value of the Python interpreter, 16 binary format such as: 0x 020403f0 Sys.version Gets the version of the Python interpreterThis information sys.maxint the largest int value sys.maxunicode the maximum Unicode value Sys.modules returns the system-imported module field, key is the module name, and value is the module Sys.path return module The search path, initialized with the value of the PYTHONPATH environment variable Sys.platform returns the operating system platform name Sys.stdout standard output Sys.stdin standard input sys.stderr error output SYS.E Xc_clear () is used to clear the current or most recent error message that occurs on the current thread Sys.exec_prefix returns the location of the platform standalone Python file installation sys.byteorder The local byte rule indicator, The value of the Big-endian platform is ' big ', the value of Little-endian platform is ' little ' sys.copyright record python copyright related things sys.api_version interpreter C API version   Sys.version_info

7. How do I copy an object in Python? What is the difference between deepcopy and copy?
Copy copies only the object itself, not the other objects referenced in the object.
Deepcopy copies the object itself, and copies other objects referenced in the object.
8, the difference between Os.path and Sys.path?
Os.path is a module that contains various functions for processing long file names (pathname).
Sys.path is a list of directory names from which Python looks for extension modules (Python source modules, compilation modules, or binary extensions). When you start Python, this list is initialized from the contents of the PYTHONPATH environment variable, as well as the registry (Windows system), based on the built-in rules.
9. What is the difference between the match and search methods in the RE module?
The match () function only checks to see if the RE is matched at the beginning of the string, and search () scans the entire string.
10. Explain the difference between generator (generator) and function, and implement and use simple generator?
The main difference between a generator and a function is that the function returns Avalue, and the generator yield a value marks or remembers point of the yield at the same time to facilitate the resumption of execution from the mark points at the next call. Yield causes a function to be converted to a generator, which in turn returns an iterator.

Only these 10 are not enough, we also have to learn the deep knowledge of python, in order to stand out from the interview.

  • 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: [email protected] 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.