+ 1
Can anyone please explain to me python indentation like i am a 10 year old?
13 Antworten
+ 7
You might find these codes helpful.
https://code.sololearn.com/cT5BRIbkia21/?ref=app
https://code.sololearn.com/cmmTiDi8mr03/?ref=app
https://code.sololearn.com/c8Tyi716A9Q7/?ref=app
+ 5
In every code block like class, function, while, for, with, try except ... you need to indent codes. This tells python that those equally indented lines are belong to same block.
That's same as curly braces in other languages.
+ 4
Explaining indentation by words is hard, it is easier to explain with images and examples. I'm anyways explaining it in words:
(Code block is code that belogs to a statement.)
(Code block statement is a statement, that contains a code block.)
Indentation is a way to indicate a code block to belong to a certain code block statement, using spaces (or tabs).
Each code block has their own indentation level, where each line of the code block must have the same amount of spaces in the start of the line.
Indentation level starts after a line, which ends with a colon : ,
and ends after a line, which has less spaces than the indentation level.
The amount of spaces of code block's indentation level does not matter, but it must have atleast 1 space more than the previous indentation level, (or the line where the colon : was, refering to its indentation level).
Maybe 10 years old wouldn't have understood.
+ 1
After any ":", you should indent once
+ 1
Błack Jesus❕
4 space doesn't help.
+ 1
Ok I'll try to explain it as simply as I can:
Basically, when you have a statement like "if" which excecutes a bunch of lines when it's True (or anything that requires adding a ":" at the end), adding indentation will help the program know which code is related to the "if" statement, meaning it will do all the code you until there are no more indentations.
Python knows that any line not indented is NOT connected to the "if" condition and will exceute them normally.
I hope this helps somehow!
+ 1
Rora
Thanks , it helps a lot.
+ 1
Furqan Ahmad Can you describe your problem?
0
confusing
0
impreesivee
0
My name is furqan pleaze help me
0
e0ger what do you mean.