+ 3

Can anyone explain me what indentation mean in python and how to remember it

Hello there developers I have started to learn python this week and as soon I have reached if statement (conditions) in python I have noticed that it's very important to learn and see how indentation really work on python otherwise python will provide a beautiful error

8th Sep 2021, 2:16 PM
Frey
Frey - avatar
9 Answers
+ 5
Ahh I get what you mean, I used to be in that problem. Don't actually use 4 spaces, use tab, it's technically 4 spaces but in 1 character. 4 spaces -" " Indentation/Tab -" " It's very identical but to not get confused, try to delete it, if it takes 2 or more tries to delete it then that means it's not a tab, if it took only 1 try then it's a tab
8th Sep 2021, 2:42 PM
Da GD Bot
Da GD Bot - avatar
8th Sep 2021, 2:58 PM
Ipang
+ 3
Python indentation is a way of telling a Python interpreter that the group of statements belongs to a particular block of code. A block is a combination of all these statements. Block can be regarded as the grouping of statements for a specific purpose. Most of the programming languages like C, C++, Java use braces { } to define a block of code. Python uses indentation to highlight the blocks of code. Whitespace is used for indentation in Python. All statements with the same distance to the right belong to the same block of code. If a block has to be more deeply nested, it is simply indented further to the right. 
9th Sep 2021, 2:31 PM
Arun Jamson
Arun Jamson - avatar
+ 2
Indentation means " " or 4 spaces. an example is x = 1 if x == 1: print("True") else: print("False") I can't explain why indentation works but I'm pretty sure it's easy to understand
8th Sep 2021, 2:27 PM
Da GD Bot
Da GD Bot - avatar
+ 2
Da GD Bot I know this but how you are going to define that how many spaces we have to use while writting code
8th Sep 2021, 2:31 PM
Frey
Frey - avatar
+ 2
Frey The indentation is the tabulation.
10th Sep 2021, 2:08 PM
CGO!
CGO! - avatar
+ 1
What do you mean by "How many spaces we have to use while writing code"?
8th Sep 2021, 2:33 PM
Da GD Bot
Da GD Bot - avatar
+ 1
Da GD Bot as Python says use 4 spaces per indentation level. like in Python 3 disallows mixing the use of tabs and spaces for indentation. and Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively." so suppose you are writing an if else statement program and you will use one step [tap] for spacings the statement and then back you come up to the else statement can we use 2 steps more space then befor ?
8th Sep 2021, 2:36 PM
Frey
Frey - avatar
+ 1
I think what you meant by it is when to use it. You should use it every time you use a statement like if statement.
8th Sep 2021, 2:36 PM
Da GD Bot
Da GD Bot - avatar