Write Inline If Statement for Print in Python



Python provides two ways to write inline if statements. These are:

1. if condition: statement

2. s1 if condition else s2

Note that second type of if cannot be used without an else. Now you can use these inline in a print statement as well. For example,

a = True
if a: print("Hello")

This will give the output:

Hello
a = False
print("True" if a else "False")

This will give the output:

False
Updated on: 2020-06-17T12:05:59+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements