You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the first line starts with an unexpected indent (a space or tab), Python will raise an IndentationError.
Example: print("Hello")
This gives: IndentationError: unexpected indent
Python expects top-level code to start at column 0 unless it's inside a block (like a function or loop). So that space is a no-no outside of those.
But in Jupyter Notebook:
Jupyter is more forgiving — it allows leading spaces in the first line of a cell even if the code is at the top level. It doesn't strictly enforce indentation rules the way a .py file would when executed.
The text was updated successfully, but these errors were encountered:
Hi @neerajpatel2505, thanks for submitting the issue. We can reproduce this in IPython directly which executes the cells in Notebook. I think the forgiveness to indention might be on purpose, but you could open a new issue in the IPython repo to discuss it or request an option to disable this current functionality.
Hi @danyeaw, thanks for your valuable response.
Your clarification makes sense — I’ll go ahead and open an issue in the IPython repo to take the discussion further.
In standard Python scripts (.py files):
If the first line starts with an unexpected indent (a space or tab), Python will raise an IndentationError.
Example:
print("Hello")
This gives:
IndentationError: unexpected indent
Python expects top-level code to start at column 0 unless it's inside a block (like a function or loop). So that space is a no-no outside of those.
But in Jupyter Notebook:
Jupyter is more forgiving — it allows leading spaces in the first line of a cell even if the code is at the top level. It doesn't strictly enforce indentation rules the way a .py file would when executed.
The text was updated successfully, but these errors were encountered: