0% found this document useful (0 votes)
22 views2 pages

Python

The document discusses the use of indentation in Python to define code blocks. It provides examples of if/else statements and nested if statements to demonstrate how indentation determines the scope of each block rather than curly braces. It also mentions the PEP 8 style guide for Python formatting.

Uploaded by

vanshikavermaasr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Python

The document discusses the use of indentation in Python to define code blocks. It provides examples of if/else statements and nested if statements to demonstrate how indentation determines the scope of each block rather than curly braces. It also mentions the PEP 8 style guide for Python formatting.

Uploaded by

vanshikavermaasr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#Python program to understand if statement

var1 = 1
var2 = 200
if var2 > var1:
print("var2 is greater than var1")

var1 = 1000
var2 = 200
if var2 > var1:
print("var2 is greater than var1")
else:
print("var1 is greater than var2")

age1 = 100
age2 = 80
if age1 > age2:
print("age1 is greater than age 2")
else:
print("age2 is greater than age 1")

var1 = 1000
var2 = 1000
if var2 > var1:
print("var2 is greater than var1")
elif var2 == var1:
print("var1 is equal to var2")
else:
print("var1 is greater than var2")

Role of Indentation in Python with Examples


The identification of a block of code in Python is done using Indentation. In many different programming languages
like C, C++, Java, etc. use flower brackets or braces {} to define or to identify a block of code in the program,
whereas in Python, it is done using the spaces or tabs, which is known as indentation and also it is generally known
as 4 space rule in Pep8 documentation of rules for styling and designing the code for Python. Let us consider an
example of this.

n = 10
if n>5:
print "n is greater than 5"
else:
print "n is not greater than 5"
Nested if

a = 10
if(a>5):
print("Inside initial if")
print("Number is greater than 5")
if(a>=10):
print("Inside first nested if")
print("Number is greater than or equal to 10")
if(a>=15):
print("Inside second nested if")
print("Number is greater than or equal to 15")
print("Outside second nested if")
print("Outside second nested if")
print("Outside initial if")

You might also like