


A must read for beginners! Top 10 underrated Python libraries!
大
In the process of learning python, everyone will understand that a powerful function of python lies in various powerful third-party library functions. You only need to install us through pip install required library functions.
People often only pay attention to the python libraries they have installed, but ignore the library functions that come with python, or the libraries that come with python. Today I will introduce to you the top ten undervalued python libraries. With a library or a function that comes with python.
1.Counter
The main purpose of Counter can be seen from the name. It is used for counting statistics. When performing data analysis or statistics, we often need to use counting. , and Counter will help us write more concise code, as shown in the figure below.
In the above program, you can see that using Counter can complete character statistics with a simple two-line program, and can also perform sorting and output operations, which greatly simplifies the code. .
2.NamedTuple
nametuple inherits the tuple class. Using nametuple, you can create a class object, and the object has accessible attributes. What is the use of this? We use the following program to explain.
In the above program, the first program in the comment does not use nametuple, and when there are too many features, we want to use one or some of them. At this time, it is not easy for us to obtain the index of the feature, which causes unnecessary trouble. When we use nametuple, we can easily access the characteristics of a specific data through the characteristic name.
3.DefaultDict
Defaultdict is a dictionary with a default initial value. When the key value we access defaultdict does not exist, it will return the default value, such as the following program:
In the program, we created a defaultdict of type int. When we want to store "python" in the dictionary, dict will report an error, and defaultdict will have an initialized default The value is 0, allowing us to easily store values by key value. Here we create a defaultdict of type int, so the default initial value is 0. When we create a defaultdict of list, the default initial value is an empty list.
4.Glob
The Glob module is mainly used to match file information under the path we specify, and return the matched absolute path of the file in the form of a list, as shown in the following figure:
In the program, we matched all jpg and png images under the path and returned their absolute paths.
5.Math
The Math module is a simple mathematical function module that comes with Python, including exponential, logarithm, sine and cosine functions.
6.Argparse
The use of the Argparse module, on the one hand, allows us to write command line interfaces, greatly beautify our programs, and make our programs look beautiful. It looks more beautiful, and on the other hand, it also makes it more convenient for us to modify the program.
In the above program, we defined two parameters a and b and stipulated that they must be input. argparse will automatically parse our input data and convert it into the specified Type (int), then our main program adds the two numbers and outputs the result. Here I just briefly show you the function of argparse. Its powerful charm needs to be reflected in a large number of programs.
7.Copy
For the copy module, it mainly involves the contents of shallow copy and deep copy. Here you need to understand the difference between shallow copy and deep copy. For deep copy, whether it is variable Whether it is an object or an immutable object, a new variable is created. For shallow copies, it is more complicated, as shown in the following figure:
Here we use a program to The above diagram is explained as follows:
As shown in the figure above, for immutable objects, shallow copy just copies the same address to the copy object. But when we modify the value of simple_str, copy_simple_str does not change. This is because the string is an immutable type, so when we modify the value of simple_str, the compiler will open up a new space, save the original value of simple_str, and let copy_simple_str point to it. For complex variable types, it can be seen from the results that the sub-objects are not completely copied, so modifying copy_complex_dict will also modify the sub-objects in complex_dict.
8.itertools
The itertools module contains many useful iterator functions, and skillful use of them can greatly improve work efficiency. Here, the editor simply gives a few examples of using itertools:
#In the above program, permutations are used to generate all permutations and combinations, and the count function is combined with zip to generate serial number. It should be noted that the permutations and count here generate iterators, which can greatly save memory space.
9.enum
In python, the enum module also implements support for enumeration types. In the enumeration collection, the enumeration members should be unique and immutable.
In the above figure we define a Week enumeration class, and then use this class to calculate the day of the week after today.
10.calendar
The calendar module is used to process calendar-related functions. For example, our most common judgment is whether it is a leap year. calendar only needs one line of program to help us complete the calculation:
In the above program, we use calendar to output whether it is a leap year, print the monthly calendar, determine the day of the week, etc. Using calendar can achieve twice the result with half the effort in dealing with calendar issues.
The above 10 python modules are very useful python built-in modules, but they are rarely used in daily programming. Through the editor’s explanation, I hope everyone can learn more about python’s built-in modules. Powerful module, you can continuously optimize your own program in future programming.
The above is the detailed content of A must read for beginners! Top 10 underrated Python libraries!. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

The key to running Jupyter Notebook in VS Code is to ensure that the Python environment is properly configured, understand that the code execution order is consistent with the cell order, and be aware of large files or external libraries that may affect performance. The code completion and debugging functions provided by VS Code can greatly improve coding efficiency and reduce errors.
