Python combat: renaming and numbering out of order files

Life is too short to learn Python! Recently, a reader friend encountered a small problem and asked Xiaowu to answer the question in private chat. I feel that there will be other students who will meet, so I just share it. PS: At present, the readership of the new book "Learn Python Quickly" has been opened, and you can join to get answers after purchasing the book. As shown in the figure below, there are such a bunch of video files in the local folder, which are not out of order in this case....

July 26, 2022

Python Concise Tutorial Series (7.1-Basic Steps for Custom Functions)

First, the basic steps of Python custom function 1. What is a function Functions, in fact, we came into contact with them when we first learned Python. But most of what we use are built-in functions of Python. print() For example, functions that appear in basically every chapter . For now, we are mainly learning about custom functions. Have you ever wondered why you need functions? To answer this question, we need to understand what a function is?...

July 26, 2022

Python Concise Tutorial Series (7.2 - Function Return Value)

2. Function return value Through the above study, you can know that the return [expression] statement is used to exit the function, selectively returning an expression to the caller. A return statement with no parameter value returns None. Concrete example: # -*- coding: UTF-8 -*-def sum(num1,num2): # 两数之和 if not (isinstance (num1,(int ,float)) and isinstance (num2,(int ,float))): raise TypeError('参数类型错误') return num1+num2print(sum(1,2)) Return result: 3 This example also isinstance()performs data type checking with built-in functions to check if the arguments are integers and floats when the function is called....

July 26, 2022

Python Concise Tutorial Series (7.3 - Parameters of Functions)

Third, the parameters of the function 1. The parameter type of the function Setting and passing parameters is the focus of functions, and Python's function support for parameters is very flexible. The main parameter types are: default parameters, keyword parameters (positional parameters), and variable-length parameters. Below we will understand these parameters one by one. 2. Default parameters Sometimes, in our custom function, if there is no parameter set when calling, we need to give a default value....

July 26, 2022

Python concise tutorial series (7.4-function passing by value problem)

Fourth, the function pass-by-value problem Let's look at an example: # -*- coding: UTF-8 -*-def chagne_number( b ): b = 1000b = 1chagne_number(b)print( b ) The final output is: 1 First look at the results of the operation? Think about why it prints 1 instead of 1000? In fact, the bottom line of the question is, why is the value of b chagne_numbernot ? This question will be covered in many programming languages, and the principle explanation is similar....

July 26, 2022

Python Concise Tutorial Series (7.5 - Anonymous Functions)

5. Anonymous functions Have you ever thought about defining a very short callback function, but don't want to use defthe form to write such a long function, so is there a shortcut? The answer is yes. Python uses lambdas to create anonymous functions, that is, no longer define a function in a standard form like the def statement. Anonymous functions mainly have the following characteristics: lambda is just an expression, and the function body is much simpler than def....

July 26, 2022

Python crawler "seal IP"? Try this free method!

Fans often leave messages in the background, asking: Boss, why did you get an error when running your crawler? I asked him to send the error message and sighed after reading it. Most of the crawler source code running errors are due to frequent visits to the target website, resulting in the target website returning an error or no data being returned. This is also the most common way, which is the "blocking IP" we often hear, which requires constant switching of IP access....

July 26, 2022

Python crawler learning route (very detailed)

This story starts from the beginning. On the first day of work in 2022, we made an important decision to create a high-quality learning route, pointing out the way forward for beginners, as well as common pit avoidance techniques. I admit that this is a very challenging thing, it tests the overall strength of a programmer. The programmer should preferably be a T-shaped person who has both in-depth research in a certain field and some dabbling in other skills....

July 26, 2022

Python data type (three): string

I'm sorry, everyone, I haven't updated for a long time due to the busy time. Today I finally have time to continue to learn python with you children's shoes. As mentioned earlier, the definition of a string is to enclose some sequence of characters in quotation marks. E.g: s = 'abc' The execution process of the above line of code: first create a string object, and initialize the sequence of string values ​​'a', 'b', 'c', and then point the pointer s to this object....

July 26, 2022

Python dynamic attributes: can be done with one parameter, not two

Article: Python Seven Author: somenzz Python has a magic function __getattr__ that can be automatically executed when an attribute of an object is called. Using this, we can implement very flexible functions. For example, to calculate the addition, subtraction, multiplication and division of two numbers, you only need to pass in one parameter to perform the calculation: File: The content of dynamic_attr_of_class.py is as follows: class DynamicAttr(object): def __getattr__(self, name): op, num = name....

July 26, 2022