43

I am using Google Colab to write Python code in their notebooks. Whenever I hit enter after a loop or conditional, the new line is automatically indented, which is good, but it uses only 2 whitespaces by default. This is contrary to the PEP-8 standard which recommends 4 whitespaces.

Why is this the case and how can I change this setting within Colab?

3
  • 2
    Quick googling got me github.com/googlecolab/colabtools/issues/15
    – tripleee
    Commented Mar 4, 2019 at 4:42
  • Note that CoCalc ("collaborative calculation in the cloud", another online platform that lets anyone use jupyter notebooks collaboratively) gives you the standard 4 spaces default. Commented Mar 5, 2019 at 4:15
  • 3
    The answer to the why question is that internally Google has long uses 2 space indentation. It's actually kinda nice once you get used to it since they also use a hanging indent of 4 spaces for things like long parameter lists, so its very easy to visually see where the hanging indent ends and where the block begins.
    – jlund3
    Commented Jan 25, 2020 at 16:41

2 Answers 2

62

You can change it to 4 whitespaces through settings:

Tools > Settings > Editor > Indentation width in spaces > Select 4

4

This is what I did

Settings / Editor / Indentation width in spaces / 4 / Save

Settings, Editor, Indentation width in spaces, 4, Save

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.