+ 2

What really is an indenting Block???

and also indention ???

27th Oct 2016, 6:23 AM
Manish27
Manish27 - avatar
7 Answers
+ 7
Indenting your code helps to improve readability of code. Python emphasis on Indentation becz like other programming languages Python doesn't use braces to tell starting and ending of block, instead Python uses indentation Like for i in myList: print (i) print ("Iterations ) print ("Loop Ended") above code works fine but this tab space (Indentation) show the start and end of the loop. If your remove the tab space for i in myList: print (i) # This will end up with error
27th Oct 2016, 6:37 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 2
So indention mean tab space , right??
27th Oct 2016, 10:35 AM
Manish27
Manish27 - avatar
+ 1
yes, indention means moving text to the right with the tab key (or at least one space).
27th Oct 2016, 10:39 PM
Alan Harrison
Alan Harrison - avatar
+ 1
Hi Manish, Indenting is used in Python for multiple reasons. Waqas provides a great detailed answer. Simply, indenting is required in order for your Python code to run properly. It also makes it easier to read, which is great when working with other coders. To indent a line of code, just hit the 'Tab' key once before typing that line or hit the 'Space' bar a few times. I hope this helps, cheers!
28th Oct 2016, 3:22 AM
Andrew Paulison
Andrew Paulison - avatar
+ 1
to understand it let a loop.. for i in range(10): print(i) i=i+1 now in these loop the 'for' is statement. The code print(i) i=i+1 is indented under the statement 'for'. A set of code is called block. So it is said that block is indented under 'for' statement or 'for' loop. why indention is used in python? for ease of read and understand the codes. In c language curly braces are used where there a loop starts. when you read code in c you often get confused in the codes. but python gives opportunity of indention so you understand each set of code easily. while in c the codes usually get mixed.
30th Oct 2016, 6:14 AM
Nayan Paliwal
Nayan Paliwal - avatar
+ 1
indentation is either tabs or spaces on the left side of a line of code. Indentation blocks refers to multiple lines that are indented the same. in most languages, developers just use indentation blocks to make code easier and quicker for developers to read and make sense of. Common times include 1) code within loops (when a section of code will repeatedly be acted on): so people can easily see what won't repeat and what will; 2) where you have different blocks of code that will run depending on some condition In python it is enforced (by errors) so that developers can't cut corners - it has the benefit is that if you are altering code you won't have deal with that particular form of hard to read code, it also allows python to not need characters to mark where loops and conditional code blocks end. (some people have strong preferences to one or the other, but the main important thing is make a choice and stick to it throughout your code)
30th Jan 2017, 1:12 AM
Phil
Phil - avatar
0
the correct word is indentation. indention is not a word.
12th Feb 2017, 4:24 AM
Jimmy Saldivias