Python has such an operator:
variable = something if condition else something_else
Alternatively, although not recommended (see karadoc’s comment):
variable = (condition and something) or something_else
More Related Contents:
- How to generate random binary numbers 0 or 1 with length of N and with option to control the probability of having 0 or 1?
- What is the python “with” statement designed for?
- What is the internal precision of numpy.float128?
- Why doesn’t a python dict.update() return the object?
- Is it feasible to compile Python to machine code?
- Speed comparison with Project Euler: C vs Python vs Erlang vs Haskell
- Wrapping a C library in Python: C, Cython or ctypes?
- It is more efficient to use if-return-return or if-else-return?
- Python (and Python C API): __new__ versus __init__
- What is the purpose of python’s inner classes?
- In python, how to capture the stdout from a c++ shared library to a variable
- What files are required for Py_Initialize to run?
- Accessing OpenCV CUDA Functions from Python (No PyCUDA)
- Why allow concatenation of string literals?
- I have Python on my Ubuntu system, but gcc can’t find Python.h
- Create an object using Python’s C API
- Can we use C code in Python?
- How to compile .c code from Cython with gcc
- Where can I find source or algorithm of Python’s hash() function?
- Difference between np.int, np.int_, int, and np.int_t in cython?
- Using Cython To Link Python To A Shared Library
- Equivalent to GetTickCount() on Linux
- Wrapping a pre-initialized pointer in a cython class
- Building Mesa for windows 7. Mesa 9.1
- C++ conversion from NumPy array to Mat (OpenCV)
- ImportError: dynamic module does not define init function (initfizzbuzz)
- Multithreading with Python and C api
- Passing numpy arrays in Cython to a C function that requires dynamically allocated arrays
- SWIG interfacing C library to Python (Creating ‘iterable’ Python data type from C ‘sequence’ struct)
- Embedding python in multithreaded C application