Understanding how to store and manipulate data with variables, and knowing the different types of data (such as integers, floats, strings, and booleans) that can be used.
Variables are like storage containers for data. In math, we usually use variable to store numerical values like integers or decimals.
<aside> đź’ˇ Variables are the storage containers in our coding kitchen to store ingredients.
</aside>
In most programming languages, you will need to declare or setup a variable using some type of statement. Here is a simple variable declaration written in Python:
x = 1
X
is the variable name
=
is what we use in most languages to declare a variable and set its value.
1
is the value
There are some best practices when it comes to naming your variables, and some languages will have specific rules and conventions to follow.
⚠️ Variables names should be meaningful and help describe what the value or data represents.
Let’s continue our food and cooking analog with variable naming conventions. Let’s say we want to create a variable that represents the amount of flour a recipe calls for.
flour_amount = 2 # 2 cups of flour
Whitespace in programming languages is generally avoided when naming
userName
, totalItemCount
user_name
, total_item_count
UserName
, TotalItemCount