Tuesday, 19 September 2017

How to write if, elif, else conditions ?


USING if / elif / else CONDITIONS

Each condition block (if / elif / else) starts with colon : 
EXAMPLE 1
grade = 75

if grade == 70:
    print("Great !")
elif grade < 70:
    print("Not so good !")
else:
    print("Wow !")


Output

Wow !


If there is only one operand in the condition, it checks if variable is not declared or None is assigned.
EXAMPLE 2
flag = None
if flag:
    print("YES")
else:
    print("NO")


Output
NO

No comments:

Post a Comment

Note: only a member of this blog may post a comment.