PYTHON LEARNING NOTES
Everything You Need To Know About Python Data Types & Variables
Crash Course Into Python Part 1 With Cheatsheet At The End
Starting with the Basics
In a nutshell, a variable is a memory location where you can store a value. This value may or may not change in the future. In Python, the declare a variable, you just have to assign a variable to it.
For example:
x = 5
x
is assigned the integer value of 5
. There are no additional commands or type declaration, unlike other programming languages.
You can also perform operations on these variables using arithmetic operators (eg: +
, —
, *
, and %
). If you declare a variable without assigning a value to it, it will give you a NameError
.
Here is an example of what the error looks like if we declare x
without any assignments:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
x
NameError: name 'x' is not defined
Variables in Python are case sensitive, which means that y
is considered as different from Y
.