Assigning Names

One of the most important functions of Python is assigning names to data. To assign any value, we use the equal to (=) symbol. Here is the format:

x = y

Here, "x" is the name of the data "y". The data type of "y" could be anything.

As you can see, the word "first" now saves a variable, "Christmas 2018". "first" is the name of the variable, as it is the name given to the variable "Christmas 2018"

Now, if we try printing out first, our output would be "Christmas 2018"

One of the most powerful features of Python is being able to manipulate these variables and values.

Here, we changed the stored variable "Hello World!" to "Python". Now, the name "first" stores the value "Python". And now if we try printing "first" we get "Python".

The length of the variable name has no limit; it can be as long as you like. But, make sure to remember that special characters, spaces, or anything starting with a number is not acceptable for the variable names. Instead of the space, we use an underscore (_). Underscore is the only special character acceptable.

Python is a case-sensitive language. Upper-case and lower-case letters should be taken into consideration, as they will change the resulting code.

Trying to print "firstprogram" gives us a NameError. It's true that we have the name "firstprogram" without the spaces, which is correct, but observing closely, we see that the 'f' and 'p' are lower-case. In order for the code to work, each word should be upper-case.