Name | Conditional Expressions |
||||||
---|---|---|---|---|---|---|---|
Examples |
s = 0 for i in range(5, 100, 5): s = 0 if i < 50 else 255 stroke(s) line(30, i, 80, i) | ||||||
Description |
A shortcut for writing an if and else structure. Conditional expressions in Python take the form expression1 if test else expression2. If the test evaluates to True, expression1 is evaluated and returned. If the condition evaluates to False, expression2 is evaluated and returned.
The following conditional expression: result = expression1 if test else expression2 is equivalent to this structure: if test: |
||||||
Syntax | expression1 if test else expression2 | ||||||
Parameters |
| ||||||
Related |
if else |
Updated on Mon Sep 21 15:53:24 2020.
If you see any errors or have comments, please let us know.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License