if else elif in Python

Take care of indenting as you will get error. The code to be executed within if condition is to be indented to create a block of code.
x=10
y=20
if(x>y):
    print("x is greater than y")
else:
    print("y is greater than x")
Output is here
y is greater than x

Using elif

If the first if condition check fails then we can for for one more check
x=10
y=20
if(x>y):
    print("x is greaeter than y")
elif(y>15):
    print("y is greater than 15")
    
else:
    print("y is greater than x but less than 15")
Output is here
y is greater than 15
Short code
x=10
y=20
if(y>x): print("x is greater than y")
Out put is here
x is greater than y
This one is easy.
x=10
y=20
print("y is big") if(y>x) else print("x is big")
Write one user defined function to filter odd and even numbers.
def my_check(x):
    return True if x%2==0 else False


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer