Which is preferred ("." indicating whitespace)?
A)
def foo(): x = 1 y = 2 .... if True: bar()
B)
def foo(): x = 1 y = 2 if True: bar()
My intuition would be B (that's also what vim does for me), but I see people using A) all the time. Is it just because most of the editors out there are broken?
Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code.
How to Avoid Indentation Error in Python? In order to not have an indentation error in Python, you must go through every line of your code separately. This will help you in understanding which line contains the error or does not have the expected whitespaces. Python arranges all lines of codes in the form of blocks.
Blank line is definitely allowed in python functions. All of yours examples (A,B,C,D) should work and the problem probably (sure) is related to "Eclipse and the PyDev plug-in".
If you use A, you could copy paste your block in python shell, B will get unexpected indentation error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With