39

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
    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. 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
    Jan 25, 2020 at 16:41

1 Answer 1

57

You can change it to 4 whitespaces through settings:

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

Your Answer

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

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