Solved

Why capital letters for constants?

FreyaLOP

Python doesn't enforce constants. Why bother with GRAVITY instead of gravity?

11

Comments 4

Join the discussion

Already have an account? Log in

  1. SophieDev Solutionreplies: 2

    It's a convention (PEP 8): UPPER_CASE tells every reader "this value is fixed, don't change it". Python won't stop you, but other developers (and linters) will.

    5
    1. FreyaLOPreplies: 1

      So it's communication, not protection.

      1
      1. JackStack

        Just realised the whole "magic number" thing is about the next person reading the code, which is often future me.

        2
    2. NoahLoops

      Exactly. And when Mars gravity comes along in stage 3, you see why named values are worth it — change one line, not ten.

      2