DEV Community

Discussion on: Python if...else statements

Collapse
 
waylonwalker profile image
Waylon Walker

Enjoying watching you as you continue learning python!

Ternary

Additionally, python does support ternary statements.

a = True
print('here') if a else print('not')
b = True if a else False
Enter fullscreen mode Exit fullscreen mode

📝 Note ternaries must have an else

pedantic comment

The cool part about this is that we can have multiple returns by using the correct indentation.

Being pedantic, each function can only have one return statement.

Collapse
 
dailydevtips1 profile image
Chris Bongers

Ah well spotted, returns is the absolute wrong word...
Multiple lines of code that get executed 😅

The ternary I've spotted after I finished the article, a welcome addition thanks! 👍