0
I have a problem with indentation. I keep getting indentation error trying the if-sratements.
4 Antworten
+ 2
Can you post a code sample that gives you an IndentationError? That would make it much easier to help you.
In general, if/else statements should look like this:
if condition:
****do_something()
else:
****do_something_else()
* denotes whitespace. Typically, four blanks are used. Missing or inconsistent use of whitespace will lead to an Indentation Error:
if condition:
do_something() # error: missing indentation
if condition:
****do_something()
else:
**do_something_else() # error: inconsistent use of whitespace
+ 1
Can you share your code?
0
Scripts of same block needs have same spacing at front of line
0
Another way to put it:
Not indenting your code in for example C will be okay for the compiler, but people having to read your code (including you) will be mad, so very likely you are going to indent anyway.
Consequently, not having to write all these brackets and semicolons any longer becomes a net plus for Python. ;-)