Python if statement

Python – Conditional Statement

Def: Conditional Statement is used to give condition in the program.  Based on the  condition’s output only a part of the program will be executed.
Ex: if statement
Types:

  1. if
  2. if-else
  3. if-elif-else

if statement
condition is set using Comparison operator and when output is true it executes the statements given.
Ex:
# Example – if statement
age = int(input(“Please enter an integer: “))
if age >= 18:
print(“Can vote in Election”)

if-else statement
else part will executed when the condition is false.
Ex:
# Example – if else statement
age = int(input(“Please enter an integer: “))
if age >= 18:
print(“Can vote in Election”)
else:
print(“Can’t vote in Election”)

Win Corporate Training
website: http://www.wincorptrg.com
View My Profile

Advertisements