Python basics#
- What is Python anyway? You can compare with other technologies in your answer.
- Python is an interpreted language. Unlike compiled languages such as C and Java, Python code does not need to be compiled before running.
- Python is a dynamic language, that is, when declaring variables, there is no need to specify the type of the variable.
- Python is an object-oriented programming language (OOP). Everything in Python is an object. Functions are objects of the first type, which means that functions can be assigned to variables. Functions can either return function types or accept functions as input.
- Python is easy to learn, and the design philosophy can refer to the Zen of Python, so that programmers don't have to deal with the low-level details.
- Python is very useful-Web programming, automation, artificial intelligence, big data and other fields shine. It is also often used as a "glue" language to help other languages and components improve their operating conditions.
- What is PEP?
- PEP8 is a programming specification that contains some suggestions on how to make your program more readable.
- What are pickling and unpickling?
- The Pickle module reads any Python objects, converts them into strings, and then uses the dump function to dump them into a file-this process is called pickling.
- On the contrary, the process of extracting the original Python object from the stored string file is called unpickling
- How is Python interpreted?
- Its source code can be run directly. The Python interpreter converts the source code into an intermediate language, and then translates it into machine code before execution.
- How does Python manage memory?
- What tools can help debug or do static analysis?
- PyChecker is a static analysis tool that can not only report errors in the source code, but also report the type and complexity of errors. Pylint is another tool to check whether a module meets the code standard.
- What is a Python decorator?
- The Python decorator is a unique change in Python that can make it easier to modify functions.
- What is the difference between array and tuple?
- The difference between an array and a tuple: the contents of an array can be modified, while the contents of a tuple are read-only. In addition, tuples can be hashed, for example as a key in a dictionary.
- How are parameters passed by value and passed by reference implemented?
- Everything in Python is a class, and all variables are references to an object. The referenced value is determined by the function, so it cannot be changed. But if an object can be modified, you can modify the object.
- What are dictionary comprehensions and list comprehensions?
- What data structures does Python have?
- What is the Python namespace?
- What is lambda in Python?
- Why is there no statement in lambda?
- What is pass in Python?
- What is a iterator in Python?
- What is unittest in Python?
* In Python, unittest is the unit testing framework in Python. It has functions that support shared setup, automatic testing, pause code during testing, iterate different tests into a group, and so on.
- What is slicing in Python?
* Slicing is a grammar that extracts a certain paragraph from an ordered object type (array, tuple, string).
- What is a constructor in Python?
* Generators are a mechanism for implementing iterators. The realization of its function depends on the yield expression, except that it is no different from ordinary functions
- What is a docstring in Python?
* A docstring in Python is called a docstring, and its role in Python is to generate documentation for functions, modules, and class comments.
- How to copy an object in Python?
* If you want to copy an object in Python, most of the time you can use copy.copy()Or copy.deepcopy(). But not all objects can be copied.
- What is a negative index in Python?
* Sequence index in Python can be positive or negative. If it is a positive index, 0 is the first index in the sequence, and 1 is the second index. If it is a negative index, (-1) is the last index and (-2) is the penultimate index.
- How to convert a number into a string?
- What is the difference between Xrange and range?
* Xrange is used to return an xrange object, and range is used to return an array. No matter how large the range is, Xrange uses the same memory.
- What are modules and packages in Python?
* In Python, modules are a way of building programs. Each Python code file is a module and can refer to other modules, such as objects and attributes.
* A folder containing a lot of Python code is a package. A package can contain modules and subfolders.
- List the member methods of python list as much as possible, and give the answer to the list operation:
- a=[1, 2, 3, 4, 5], a[::2]=?, a[-2:] = ?
- One line of code realizes the summation after adding 3 to the even-numbered elements in list a?
- Disrupt the order of the elements of list a, then sort a to get list b, and then construct a dictionary d from a and b in the order of elements.
- Use python to count the occurrence frequency of each word in an English article, and return the top 10 words with the highest occurrence frequency and the number of occurrences, and answer the following questions? (Punctuation marks can be ignored)
- After creating the file object f, explain the difference between the readlines and xreadlines methods of f?
- Additional requirement: The element within the quotation marks needs to be counted as a word, how to achieve it?
- Briefly describe the concept of python GIL and its impact on python multithreading? Write a multi-threaded crawling webpage program, and clarify whether the multi-threaded crawling program can be compared with single-threaded performance improvement, and explain the reason.
- Use python to write a thread-safe singleton mode implementation.
- Explain the concepts of decorators, descriptors (property), and metaclasses, and enumerate their application scenarios;
- How to dynamically get and set the properties of an object.
- How to copy an object in Python? (The difference between assignment, shallow copy and deep copy)
- Introduce the usage and function of except?
- How to use Python to query and replace a text string?
- What is the difference between match() and search() in Python?
- When matching HTML tags with Python, what is the difference between <.> and <.?>?
- How to generate random numbers in Python?
- Is there a tool that can help find python bugs and perform static code analysis?
* PyChecker is a static analysis tool for python code, it can help find bugs in python code,Will warn about the complexity and format of the code
Pylint is another tool for codingstandard checking
- How to set a global variable in a function?
- What is the difference between single quotes, double quotes and triple quotes?