Last modified: Jan 10, 2023 By Alexander Williams

inline if statement python

Inline if statement

1
2
3
x=1z='yes!'ifx==1else'no'print(z)

output

1
yes!

Same example with normal if statement

1
2
3
4
5
6
7
8
x=1ifx==1:z='yes!'print(z)else:z='no!'print(z)

output

1
yes!