The curse, 90% of friends who have not learned Python programming for three months will make mistakes!


The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

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!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

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:

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

Advanced advanced: recursive use of python crawler

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

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.

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

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:

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

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!

The curse, 90% of friends who have not learned Python programming for three months will make mistakes!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325889430&siteId=291194637