+ 1
I don't understand the indentation . How to do it
6 Respuestas
+ 17
This is not indented.
This is indented.
This is also indented.
Indented at same level as line 3.
This is not indented.
+ 13
spacebar or tab
+ 11
You just need to remember to indent the lines of code constituting a logical block. The indentation jump has to be consequent throughout the code. Whenever you have a block of code like method definition, loop or if/else statement, you make an indent and if it is nested, you make another indent each time it is needed. For example:
def my_func(x): # no indentation
if x == 3: # one indentation jump, I chose 4 spaces
print(x) # two jumps, so 8 spaces altogether
else: # back to one-indentation jump
print(2) # again two jumps, as this is a logical subblock of code in the if/else statement
+ 10
I suggest Tab ↔️
+ 5
In Python, indentation is a bit tricky, another language like Java would take {} (braces) to show which statements lie within a block.
In Python you need to use indentation, and things become tricky, because due to even one small mistake in indentation, you may fall into bad and ugly errors.
I suggest, for small codes, you should first write the code without indent, commenting with
#{
and
#}
The opening and closing of a block.
After you have written the code, you should start indenting.
Hope I helped...
+ 5
@Ahri, short and sharp😂😂😂