Assigning variables in Python
Variables are named placeholders we can use to store and manipulate data. Variables point to a portion of the memory in which the data is stored. The kind of data that is stored within the memory portion that a variable is pointing to is known as the data type of that variable. These data types can be, for example, a string for text or an integer for a whole number. While some programming languages (such as C++ or Java) require you as the developer to explicitly define what kind of data you want to put into a variable, Python is dynamically typed. This means that the programming language will take care of assigning the correct data type to your variable, based on what you are putting in.
In this recipe, you will see how to assign variables in Python using the =
operator and see the basic data types Python offers.
Getting ready
Open your code editor and start by creating a file called variables.py
. Next, navigate your terminal to the same directory...