
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Why is indentation important in Python?
Many a times it is required to treat more than one statements in a program as a block. Different programming languages use different techniques to define scope and extent of block of statements in constructs like class, function, conditional and loop. In C and C++ for example, statements inside curly brackets are treated as a block. Python uses uniform indentation to mark block of statements.
Before beginning of block symbol : is used. First and subsequent statements in block are written by leaving additional (but uniform) whitespace (called indent) . In order to signal end of block, the whitespace is dedented. Following example illustrates the use of indents in Python:
num = int(input("enter number")) if num%2 == 0: if num%3 == 0: print ("Divisible by 3 and 2") else: print ("divisible by 2 not divisible by 3") else: if num%3 == 0: print ("divisible by 3 not divisible by 2") else: print ("not Divisible by 2 not divisible by 3")
Note: It is important to ensure that all statements in a block at particular level should have same indentation.
- Related Articles
- Lines and Indentation in Python
- Detection of ambiguous indentation in python
- Statement, Indentation and Comment in Python
- Why is Algebra important?
- Why is light important?
- Why Is CRM So Important?
- Why is electricity so important?
- Why is crop protection important?
- Why Sustainability is Important in Project Management?
- Why sorting of materials is important?
- Why is ploughing important for plants?
- Why is transpiration important for plants?
- What is DevSecOps and Why it is Important?
- Why is water management important for us?
- Why is conservation of natural resources important?
