PEP 308 adds a ternary operator:
foo = "True" if test else "False"
It’s been implemented since Python 2.5
More Related Contents:
- Static methods in Python?
- Finding and replacing elements in a list
- How to use a variable inside a regular expression?
- Rotate axis text in python matplotlib
- Python’s most efficient way to choose longest string in list?
- Is there a way to pass optional parameters to a function?
- Python sockets error TypeError: a bytes-like object is required, not ‘str’ with send function
- Bin elements per row – Vectorized 2D Bincount for NumPy
- Capture arbitrary path in Flask route
- Shifted colorbar matplotlib
- Is there a difference between QFileDialog strings in PyQt4 and PyQt5?
- Numpy argsort – what is it doing?
- Efficiently updating database using SQLAlchemy ORM
- How can I use boto to stream a file out of Amazon S3 to Rackspace Cloudfiles?
- Installing MySQL Python on Mac OS X
- How to create a tree view with checkboxes in Python
- Should I use `import os.path` or `import os`?
- Python a, b = b, a +b
- Tkinter have code for pages in separate files
- How to clear memory completely of all matplotlib plots
- Python extend with an empty list bug? [duplicate]
- How do I set a proxy for phantomjs/ghostdriver in python webdriver?
- Named colors in matplotlib
- Why do we need the “finally” clause in Python?
- 3d Numpy array to 2d
- Are Generators Threadsafe?
- setup_requires with Cython?
- Why is the first element in Python’s sys.path an empty string?
- Image Cropping using Python
- What is the difference between `extras_require()` and `install_requires()` in setup.py?