This issue has compiled some basic pythonTips to prevent pitfalls, I hope Helpful to everyone. ##1. Chain operation
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
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:
## 4. Remove elements from the list
Note: The removal operation of the list will change the index of the original list element.
5. and =
#Note: a = a [5,6,7,8] creates a new list, a = [5,6,7,8 ] Expanded the original list. 6. sorted/reversed
## Note: The sorted method returns a list, and the reversed method returns an iterator. 7. **
# Note: True, False converted to 1, 0. 8. List/Dictionary update
# #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
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!