Variables and Data Types in Python
Variables:
In programming, a variable is a named location used to store data in memory.
It is called a variable because its value can vary throughout the execution of a program.
Variables must be given unique names, called identifiers. In Python, variable names are case
sensitive
and cannot start with a number. They can contain letters, numbers, and underscores.
Example:
apples = 5
Now, apples is a variable that stores the value 5.
We can use this variable in calculations, such as adding more apples:
apples = apples + 3
print(apples)
This will output 8, because we added 3 to the value stored in the apples variable.
Data Types:
A data type is an attribute that tells what kind of data a particular variable can hold.
There are several basic data types in Python:
1. int (Integer):
Whole number, positive or negative, without decimals.
Example:
num_apples = 10
num_oranges = -5
Variables:
In programming, a variable is a named location used to store data in memory.
It is called a variable because its value can vary throughout the execution of a program.
Variables must be given unique names, called identifiers. In Python, variable names are case
sensitive
and cannot start with a number. They can contain letters, numbers, and underscores.
Example:
apples = 5
Now, apples is a variable that stores the value 5.
We can use this variable in calculations, such as adding more apples:
apples = apples + 3
print(apples)
This will output 8, because we added 3 to the value stored in the apples variable.
Data Types:
A data type is an attribute that tells what kind of data a particular variable can hold.
There are several basic data types in Python:
1. int (Integer):
Whole number, positive or negative, without decimals.
Example:
num_apples = 10
num_oranges = -5