Can a variable name start with a number?

JackStackOP

I wanted 2nd_stage = "fuel" and got SyntaxError. Rules?

0

Comments 5

Join the discussion

Already have an account? Log in

  1. Grace_42replies: 2

    Names can contain letters, digits and underscores, but can't start with a digit. Use second_stage or stage_2.

    Also avoid built-in names like list, str, sum — Python allows them but you'll break the built-in for the rest of the file.

    4
    1. JackStackOPreplies: 1

      Oh, I did name something sum yesterday and then sum([1,2]) stopped working. That's why!

      0
      1. LucasVD

        Classic! del sum brings the built-in back in the same session, by the way.

        1
    2. SamPrice

      Python convention is snake_case for variables: fuel_level, not FuelLevel or fuellevel.

      4
      1. HenryWrites

        And names are case-sensitive, Speed and speed are two different variables. Found that out the hard way.

        1