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?
Similar Posts
- Use of else condition with for loop in Python
- Python - regex , remove all single characters,replace all single chars,char
- If else conditions python
- Use of try, except, else and finally in python
- Assign multi-line string to a variable in python
- One line code to get the sum of a list in python
- Python Strings: Learn How to Add Line Breaks