Last modified: Jan 10, 2023 By Alexander Williams
inline if statement python
Inline if statement
1 2 3 | x = 1 z = 'yes!' if x == 1 else 'no' print(z) |
output
1 | yes! |
Same example with normal if statement
1 2 3 4 5 6 7 8 | x = 1 if x == 1: z = 'yes!' print(z) else: z = 'no!' print(z) |
output
1 | yes! |