python
If else conditions python
x = 50
y = 30
if x > y:
print("x is greater than y")
elif x == y:
print("x equals to y")
else:
print("y is greater than x")
Output
x is greater than y
The code snippet shows the nested if-else example. we use 'elif' keyword in place of else if which is used in most of the programming languages. In the code snippet, we have compared values of x and y variables.
If the value of x is greater than y - it will print 'x is greater than y'
If the value of y is greater than y - it will print 'y is greater than x'
If the value of x equals to y - it will print 'x equals to y'
Was this helpful?
Similar Posts
- Apply join based on multiple conditions SQLAlchemy
- Single line if else condition python
- Use of else condition with for loop in Python
- Use of try, except, else and finally in python
- Python Measure the execution time of small bits of Python code with the timeit module
- [Python] Use json.dumps() to pretty-print Python dicts
- [Python] The get() method on Python dicts and its "default" arg