You are using it wrong. Use it this way:
a = 2 if i in [1, 3, 6] else 7
The general form is:
var = val1 if cond else val2
More Related Contents:
- Conditional Replace Pandas
- Replace all elements of Python NumPy Array that are greater than some value
- How to do/workaround a conditional join in python Pandas?
- Conditional with statement in Python
- How to create a conditional task in Airflow
- How to have multiple conditions for one if statement in python [duplicate]
- Detecting Vowels vs Consonants In Python [duplicate]
- How do I assign values based on multiple conditions for existing columns?
- Set value of one Pandas column based on value in another column
- Multiple ‘or’ condition in Python [duplicate]
- How to do a conditional decorator in python?
- “or” conditional in Python troubles [duplicate]
- Assignment Condition in Python While Loop
- raise statement on a conditional expression
- Python pandas – new column’s value if the item is in the list
- Pandas: Join dataframe with condition
- How to make a dict from n’th indices of tuples in list
- Changing default encoding of Python?
- List comprehension with if statement
- Python list doesn’t reflect variable change
- What do square brackets, “[]”, mean in function/class documentation?
- How to use Paramiko logging?
- Why is semicolon allowed in this Python snippet?
- numpy: formal definition of “array_like” objects?
- Power BI: How to use Python with multiple tables in the Power Query Editor?
- python recursive function that prints from 0 to n?
- Loading .RData files into Python
- on_member_join and remove dont work. How to make it work?
- environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON
- Annotating a 3D scatter plot