Why do I get an error using 1st as a variable name?

stuck with the last few questions in this course. Everytime I try and use 1st as an element name I get a syntax error until I change it to first or something similar. Is it an issue with the course or is there a different way to declare a parameter starting with an integer?

Hi seanos90!

I don’t think I have thought or tried to use a number in a variable like this yet. These types of questions :definitions and rules are easy to look up on the internet. Since I haven’t come across this yet (as a newer learner myself) I did some research, and it appears that you can’t have a variable start as a number.

The Rules

  • Variables names must start with a letter or an underscore, such as:
    • _underscore
    • underscore_
  • The remainder of your variable name may consist of letters, numbers and underscores.
    • password1
    • n00b
    • un_der_scores
  • Names are case sensitive.
    • case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable.

Try to use an underscore before your _1st and see if that will work. The internet is pretty easy to find things like this. Thanks, I learned something new as well!

1 Like

This is why we recommend not using l as a variable, it can be confused with 1.

lst

is a common name given to list objects in sample and exercise code. That is, elle-ess-tee, not one-ess-tee.

As mentioned above, variable names may not begin with a number, but may contain a number.

2 Likes

Thank you for your reply :slight_smile: and Completely get that now, I ended up googling it too after a few more tries. I just don’t get why codecademy would use 1st in the exercises?

1 Like

The one looks like an elle, but if we check the lesson, I’m betting it is lst, not 1st.

The why of it is representative of list, but we should avoid using reserved words as variable names so the author wrote, lst. Other authors make it more obvious by using, my_list or alist, etc.

I make it obvious by using a font where different characters look different