Chrome Extension

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()
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Was this helpful?
0 Comments
Join Devsheet Ask a Question