Although the Python language is beautiful, concise and powerful, it also has many pits, which will fall into it if you are not careful. I also encountered it when I was learning Python. I will summarize it today, and I hope it can be beneficial to everyone!
Python's default parameters are created once, not every time the function is called. That is to say, changes to this list in the following code will also modify the previous content!
If you don't believe me, you can print the address of res to see:
Advanced advanced: recursive use of python crawler
I parse the page of a web page and get the result of parsing. If the current number of pages exceeds the maximum number of pages, stop, otherwise continue to recursively parse the next page, here is res=None, recursion is quite useful.
Closure is a relatively difficult concept to understand in Python. It is often combined with function decorators, plus an anonymous function, and my head is dizzy! Let's change the way of ordinary functions to understand:
There are many fun and interesting scenery on the road of Python learning, and there are also many pits. You are welcome to discuss together. If you have any questions, you are welcome to come!