Legacy - Naming and Storing Variables
- 01:33
Learn the convention of naming variables in python.
Downloads
No associated resources to download.
Transcript
Let us now look at how to name variables in Python. There are some conventions for naming in Python that needs to be followed. The slide above shows some examples of what is right and wrong when naming variables. But what is a variable? A variable is a reserved memory location to store values. It gives the computer data for processing. Firstly, we are allowed to have lowercase words but are not allowed to have hyphens between words. One thing to note is that variables are case sensitive. So we are allowed to have two words together, starting with uppercase letters, or in any other order of uppercase and lowercase letters. But without any spaces. The solution to not having any spaces or hyphens is to have an underscore in between words. By using this we can represent variables, which need more than one word to make sense. Furthermore, we cannot start words with a number but can rather end words with numbers. We cannot also have special characters when naming variables like quotations or other characters. This is because more special characters in Python have a meaning and it performs an operation. These are the more important standard conventions that needs to be followed. We can also refer to the PEP 8 Guide, which is an unofficial guide to describing the conventions in Python.