Commenting should be flexible for coders. And for that comments should not follow indentations
And some times in bigger codes it gives IndentationError
Moved to Python Help. Please see this recent thread: No more Indentation problems
This shouldn’t happen. Can you give an example of a comment that is causing an indentation error? Wrap your code in triple backticks (```) or select the text and use the code-formatting button </> to make sure we can view it correctly.
You most likely used a docstring as a comment. Although a docstring can often be effectively used as a comment since a string literal alone does nothing, it is really an expression like any other and has to follow the indentation rules.
For example, this is OK:
for i in range(3):
'''output 0, 1, 2'''
print(i)
This is not OK:
for i in range(3):
'''output 0, 1, 2'''
print(i)
An actual #-led comment though has no indentation restrictions, so this is OK:
for i in range(3):
# output 0, 1, 2
print(i)
1 Like