python

Single line if else condition python

You can use if-else condition as a ternary operator in python and can execute them in a single line by this code

def hellPrint():
    myvar = "1"
    message = "Condition is true" if myvar == "1" else "Condition is false"
    print(message)
    
hellPrint()
Was this helpful?