What is if-else in python

Python Conditions and If statements


Python helps the standard logical situations from mathematics:

Equals: a == b
Not Equals: a != b
Less than: a < b xss=removed> b
Greater than or same to: a >= b
These situations may be utilized in numerous ways, maximum normally in "if statements" and loops.

If else in python



An "if statement" is written via way of means of the usage of the if keyword.

Example:
If Statement:
a = 33
b = 200
if b > a:
  print("b is greater than a")

If  Else

Else
The else key-word catches something which isn`t stuck via way of means of the previous conditions.

Example:
if Else:
a = 200
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")
else:
  print("a is greater than b")

Elif

The elif key-word is pythons manner of saying "if the preceding situations have been now no longer true, then do this condition".

Example Elif :
a = 33
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")

And

The and key-word is a logical operator, and is used to mix conditional statements:

Example And:
a = 200
b = 33
c = 500
if a > b and c > a:
  print("Both conditions are True")

Or

The or key-word is a logical operator, and is used to mix conditional statements:

Example Or:
a = 200
b = 33
c = 500
if a > b or a > c:
  print("At least one of the conditions is True")

Nested If

You could have if statements interior if statements, that is referred to as nested if statements.

Example :
x = 41

if x > 10:
  print("Above ten,")
  if x > 20:
    print("and also above 20!")
  else:
    print("but not above 20.")

The Pass Statement

if statements can not be empty, however in case you for a few cause have an if announcement and not using a content, placed with inside the pass Statement announcement to keep away from getting an error.

Example:
a = 33
b = 200

if b > a:
  pass

Comments