Python if Statement

If statements is a statement which is used to test any condition and if the condition is True then executes True block.


Syntax of using if statement

(if expression/condition) :
               //statements to execute when condition become true 


x=10
if x==10:
	print("value of x is 10")
value of x is 10

Example of if


# taking input from user
# input()-function is used to take input 
var=input("enter your name ")
if var=="ram":
	print("Hello , Welcome")
enter your name ram
Hello , Welcome

input()- This function is used to take input from user.

Example : expression in if


# we can use expression directly inside the if condition
# example :
x=3
y=5
z=60
if(x+y+z):
	print("Yes true block")
Yes true block

Example: string in if statement


# we can pass string into if condition 
x="hey , this is python"
if(x):
	print("This is true block ...")
This is true block ...

Example: integer and float type variable in if statement


# we can also pass integer and float values in if
x=34
y=45.54
if(x):
	print("integer type variable in if")


if(y):
	print("float type variable in if")
integer type variable in if
float type variable in if