


We have compiled 12 essential Python functions. It is recommended to collect them.
Apr 12, 2023 pm 05:10 PMPreface
Novices tend to get stuck when writing code, especially when they are exposed to a lot of functions and other knowledge. They often read the requirements after reading them. Later, I don’t know what method I should use to implement it. You may have the logic to implement it, but you have forgotten which function to use. This is actually because you have insufficient knowledge reserves. You can’t remember which function does what, and you are naturally confused. water.
In the past few days, I have specially compiled some commonly used functions in Python, from the most basic input and output functions to 12 sections such as regular expressions. There are a total of more than 100 commonly used functions, which is convenient for friends to quickly To memorize it, go through it quickly every day, and deepen it when you use it. Slowly you will get rid of the situation of being stuck in writing code.
Although when we learn programming by ourselves, we emphasize more on understanding and actually typing code, there are some things you must keep in mind, otherwise it will be difficult for you to write code. Of course, veterans have already memorized them. If novices want to develop quickly and easily, it is a good way to memorize frequently used functions.
1. Basic function
#Case: Convert floating point value to string and output the converted data type
1 2 3 4 |
|
2. Process control
#Case: Judge the score based on the score entered by the user. When it is less than 50 points, it will prompt "Your score is less than 50 points", when the score is 5059, it prompts "your score is around 60 points", 60 points or more is considered a pass, 8090 points is excellent, and more than 90 points is excellent.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
3. List
#Case: Determine whether the number 6 is in the list [1,2,2,3,6,4,5 ,6,8,9,78,564,456] and output its subscript.
1 2 3 4 |
|
4. Tuple
Case: Modify tuple
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 |
|
5. Character String
Case: Use format() in three ways to output a string
Method 1: Use numbers to account Digit (subscript):
1 2 3 4 5 6 |
|
Method 2: Use {} placeholder:
1 2 3 4 5 |
|
Method 3: Use letter placeholder:
1 2 3 4 |
|
6. Dictionary
Case: Find data in dictionary:
1 2 3 4 5 6 |
|
7. Function
Function this The highlight of the block is more custom functions. There are not many commonly used built-in functions. The main ones are the following:
Case: In Define a local variable in the function, and the variable can still be called when exiting the function
1 2 3 4 5 6 |
|
1 2 3 |
|
8. Processes and threads
Case:Inherit Thread class implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
9. Modules and packages
Case: How to use packages 4 :
1 2 3 |
|
10. File operation
(1) Conventional file operation
About the conventional mode of file operation:
Object properties of file
file对象的方法
(2)OS模块
- 关于文件的功能
- 关于文件夹的功能
11. 修饰器/装饰器
案例:classmethod的用法举例:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
12. 正则
案例:用split()函数分割一个字符串并转换成列表:
1 2 3 4 5 |
|
结语
这篇文章的目的,不是为了教大家怎么使用函数,而是为了快速、便捷地记住常用的函数名,所以没有把每个函数的用法都给大家举例,你只有记住了函数名字和它的作用之后,你才会有头绪,至于函数的用法,百度一下就出来,用了几次你就会了。
如果连函数名和它的用途都不知道,你要花的时间和精力就更多了,必然不如我们带着目的性地去查资料会更快些。
The above is the detailed content of We have compiled 12 essential Python functions. It is recommended to collect them.. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

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

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

Complete collection of excel function formulas

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing
