1.3 The art of naming
Python is relatively flexible about what you name your variables but rather picky about the format of names.

I could have chosen or even for my variables. If a box in your attic were labeled or though, would you know what it contains a year later? So, although you can, it’s better not to use cryptic, general, or very long names.
You can’t use spaces to separate words in a name, you can’t start a name with a digit and names are case-sensitive, i.e. and are not the same variable. Making one of those mistakes will result in a syntax error (when the computer doesn’t understand the line of code) or a name error (when the computer doesn’t know of any variable with that name).
Let’s see some examples. (Remember that you’re not expected to write any code for this step.) The first example has spaces between the words, the second example has a digit at the start of the name, and the third example changes the case of a letter, resulting in an unknown name. The kind of error is always at the end of the error message.
deaths In Portugal = 140
File "<ipython-input-7-ded1a063fe45>", line 1
deaths In Portugal = 140
^
SyntaxError: invalid syntax
2013deathsInPortugal = 140
File "<ipython-input-8-af085101fcfc>", line 1
2013deathsInPortugal = 140
^
SyntaxError: invalid syntax
deathsinPortugal
---------------------------------------
NameError Traceback (most recent call last)
<ipython-input-9-7d3c81b4fb34> in <module ()
----> 1 deathsinPortugal
NameError: name ‘deathsinPortugal’ is not defined
Note that Jupyter doesn’t write any because the code is wrong and thus doesn’t generate any output.
In this course, to make names shorter to help fit lines of code on small screens, we’ll use capitalisation instead of underscores to separate the different words of a name, as shown in the code so far. Such practice is called camel case independently of the name having oneHump (‘dromedary case’ just doesn’t sound good, does it?) or moreThanTwoHumps . The convention in Python is to start variable names with lower case and we’ll stick to it.
In the next section, download the notebook for this week and work through the first exercise – your first line of code!
OpenLearn - Introduction and guidance
Except for third party materials and otherwise, this content is made available under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 Licence, full copyright detail can be found in the acknowledgements section. Please see full copyright statement for details.
