Tips | A few Python tips that 99.9% of people will make mistakes!

Release: 2023-08-09 17:09:55
forward
524 people have browsed it


This issue has compiled some basic pythonTips to prevent pitfalls, I hope Helpful to everyone.

##1. Chain operation

Tips | A few Python tips that 99.9% of people will make mistakes!

Note: Refer to common chain operations: 1<5<10

##2 .is operator

Note: Some values ​​​​often used in Python are defined as small integer pools. The range of the small integer pool is [-5,256]. Python has already processed these values ​​​​in advance. After the memory space is created, even if it is redefined multiple times, a new space will not be opened up again, but the values ​​outside the small integer pool will be opened up again when redefined,Different edits Servers may vary on different platforms.

3. all() function

Tips | A few Python tips that 99.9% of people will make mistakes!

Note: all() function is used to determine whether all elements in the given iterable parameter iterable are True. If so, it returns True, otherwise it returns False. Elements are all True except 0, empty, None, and False. The function is equivalent to:

Tips | A few Python tips that 99.9% of people will make mistakes!

## 4. Remove elements from the list

Tips | A few Python tips that 99.9% of people will make mistakes!

Note: The removal operation of the list will change the index of the original list element.

5. and =

Tips | A few Python tips that 99.9% of people will make mistakes!

#Note: a = a [5,6,7,8] creates a new list, a = [5,6,7,8 ] Expanded the original list.

6. sorted/reversed

Tips | A few Python tips that 99.9% of people will make mistakes!

## Note: The sorted method returns a list, and the reversed method returns an iterator.

7. **

Tips | A few Python tips that 99.9% of people will make mistakes!

# Note: True, False converted to 1, 0.

8. List/Dictionary update

Tips | A few Python tips that 99.9% of people will make mistakes!

# #Note: Updates to lists and dictionaries are done in situ Modify the object and return None to improve performance.

9. Mutable objects/immutable objects

Note: Mutable objects (such as list) can be changed in functions, while immutable objects (a -= 1 ) is not a change in value.

10. Guess

Tips | A few Python tips that 99.9% of people will make mistakes!

Reference:

https://docs.python.org/3/reference/simple_stmts.html#assignment-statements

The above is the detailed content of Tips | A few Python tips that 99.9% of people will make mistakes!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:Python当打之年
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!