Literals and Variables

Some of my users gave me grief on the brevity of my last two videos so here's one that pushes the limit - running about 10 minutes.

Literals are any values you can see in the code itself.

For instance,

print("Hello, World")

The string "Hello, World" is the literal.

Literal values can then be stored in variables and utilized:



This is opposed to if we were to ask a user his name then print a personalized message:

name=input("What is your name?")


In this example the user's name never shows up in code. This program will take user input and output it. It can accommodate any name that anyone enters.

Literals can be of any type:



Variables are containers for values. You can store a value in a variable and utilize that variable as if it were a literal value.

The assignment operator looks like the single equal sign. It reads and evaluates what is on its right, and assigns it to what is on its left.


Therefore: WE KNOW that if there is a single equal sign, the thing on its left MUST be a variable. Also WE KNOW that the thing on its right MUST be or evaluate to a value.


In this example we assign 123 to the variable x:


In this example we assign 3.1415926 to the variable pi


In this example we assign the value 27 to the variable y


Do not confuse single and double equal signs. = assigns, == evaluates equality.

Finally, Python is not Math: = assigns, it does not describe. That's why we can say:




6 will be printed to screen...

1. 5 is assigned to x

2. 5+1 is evaluated and assigned to x (thereby removing the previous value of 5)

3. 6 is printed

Next Post: Math (Built-in)

Recent Posts

© 2019