Python Indentation
Indentation refers to the spaces at the beginning of a code line.
Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.
#LearningForIndia #python #ASMR
Reference link - https://www.w3schools.com/python/pyth...
Indentation in Python is simply the spaces at the beginning of a code line. Indentation in other languages like c, c++, etc., is just for readability, but in Python, the indentation is an essential and mandatory concept that should be followed when writing a python code; otherwise, the python interpreter throws IndentationError.
What is Indentation in Python
Indentation is the leading whitespace ( spaces and tabs ) before any statement in python. The reason why indentation is important in python is that the indentation serves another purpose other than code readability. Python treats the statements with the same indentation level (statements with an equal number of whitespaces before them) as a single code block. So whereas in languages like c, c++, etc. a block of code is represented by Curly braces { }, in python a block is a group of statements that have the same Indentation level i.e same number of leading whitespaces.
Below are some of the observations that can be made from the above figure:
1. All the statements which are on the same level of Indentation(Same no of whitespaces before them) belong to a single block, so from the above diagram, statements in line 1, line 2, and line 7 belong to a single block, and the block has the zero or lowest level of indentation. Statements 3 and 5 are indented one step, forming another block at the first level of indentation. Similarly, statements 4 and 6 are indented two steps, so they together form another block at the second level of indentation.
2. Below the line 2 statement, which is an if statement, statements 3 and 5 are indented one step; hence, they belong to a single block. And since line 2 is an if statement, the block indented below the if forms the body of if. So here, the body of the if statement at line 2 includes all the lines that are indented below it, i.e., lines 3,4,5 and 6.
Now that we know that statement at line numbers 3,4,5 and 6 forms the body of the if statement at line 2. Let us understand the indentation for them. Statements at 3 and 5 are uniformly indented, so they belong to a single block (block2 from the interpretation), and they will be executed one by one.
3. Statement at line 4 makes up the body of the if statement at line 3, as we know any statements that are indented below an if form the body of if statement, similarity the statement at line 6 makes up the body of else statement at line 5.
This is how the indentation helps define the blocks and also to identify to which statements the block belongs.
What is Indentation in Python,
How to indent your python code,
How to avoid python indentation errors,
Python Indentation Rules,
Benefits of Indentation in Python,
Disadvantages of indentation in Python
Python Indentation & Syntax ASMR - this video describes you about what is python indentation.
what are the common python indentation errors ?.
what is indentation in python hindi. in this video we are going to learn indentation in python how indentation work how to maintain indentation while working with python..
python indentation - how to fix python indentation error.
how to solve python indentation error? indentation in python (hindi). to know more about python indentation: ..
python indentation error blog article (how to resolve):..... explaining python indentation error when mixing tabs and spaces.
and why is python indentation is important. what is python indentation ?.
how to fix python indentation errors ?.
This video describes you about what is python indentation.
In this video we are going to learn indentation in python how indentation work how to maintain indentation while working with python..
What are the common python indentation errors ?.
Python indentation - how to fix python indentation error.
How to fix python indentation errors ?.
And why is python indentation is important.
Explaining python indentation error when mixing tabs and spaces.
Python indentation error blog article (how to resolve):.....
To know more about python indentation: ..
Python indentation - how to fix python indentation error.
How to solve python indentation error?
Watch video Python Indentation & Syntax | CodeWithKris | Day 11 - ASMR ( No Talking ) online without registration, duration hours minute second in high quality. This video was added by user CodeWithKris 26 March 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 2 once and liked it 1 people.