Skip to main content

Varaibles and Types

Variables are used for the purpose of storing data values. I like to think of variables as a label assigned to a value. In Python you can create a variable using the assignment operator =. Below are two examples of creating variables called x and y.

# An example showing you how to assign a variable
x = 10
y = "python"
print (x)
print (y)

Dynamic Type

Unlike other languages, in Python a variable is not confined to the value you have assigned it, but rather fluid and can change whenever you want the value of your variable to change. In the example below we assign x to the number 10 (float) and then reassign it to "python" (String). We can check its type using the type function.

x = 10
print(type(x))

x = "python"
print(type(x))