How python simplifies if statements
This article is about how python simplifies if statements. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Simplify if statement
We can validate multiple values in the following ways:
If m in [1,3,5,7]:
Instead of:
If masks 1 or masks 3 or masks 5 or masks 7:
Alternatively, for the in operator, we can use'{1mage3, 5, 5, 7} 'instead of [1, 3, 5, 5, 7], because fetching elements in set is an O (1) operation.
Thank you for reading! This is the end of the article on "how python simplifies if sentences". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!