In Python, ʻin is part of the
forand can also be used as an operator to find out if a value is included as an element of a container such as
list or
tuple`. If you use it well, you can make Pythonic expressions.
In the following example, if the list sys.argv
containing the command line arguments contains the string --debug
, then DEBUG
is set to True
, otherwise False
is set. Will be done.
DEBUG = '--debug' in sys.argv
You can also use not in
as the opposite:
SHORT = '--verbose' not in sys.argv
Recommended Posts