

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Why is water management important for us?
- Why is conservation of natural resources important?
- What is data mining and why is it important
- What is cyber hygiene, and why is it important?
- Why it is important to sleep at noon?
- Why is it important to secure IoT devices?
- Lines and Indentation in Python
- What Is the Kyoto Protocol and Why Is It Important?
- Why is it important to create a Data Backup?
- Why is case sensitivity so much more important in JavaScript?
- Detection of ambiguous indentation in python
- Statement, Indentation and Comment in Python
- Why is it important to play outdoor games for kids?
- Why college reunions are an important ritual?
- Why is it important to discover your career passion, and how?