Ternary Operator in Python

This is the short hand name of if - else. It is also know as conditional operator. Its allow to test the condition in single line.

Syntax :-

[on_true] if [expression] else [on_false]

Example :-

a,b = 7,5
print(a) if a>b else print(b)
max = a if a>b else b
print(max)
Python

Output :-

7
5
Markup

I hope you understand the concept of ternary operator in python. If you have any suggestion or query please do a comment.

Thank You.

Comments

Popular posts from this blog

⚠️How to create a virus in termux app ?

List in Python

How To Install Metasploit In Termux App ?