Data Types and Variables
In Course course one, understanding the different data types and how to declare variables is essential. Data types define the kind of values that can be stored and manipulated, while variables provide a way to label and store values.
Common Data Types
Let's take a look at some common data types in Python:
- Integer: Represents whole numbers without decimal points, such as 1, 10, -5.
- String: Represents a sequence of characters, surrounded by single or double quotes, such as "hello", 'world'.
- Float: Represents numbers with decimal points, such as 3.14, -2.5.
- Boolean: Represents either True or False.
Declaring Variables
Variables in Python are declared using the following syntax:
1variable_name = value
For example, let's declare some variables:
1age = 25
2name = "John Doe"
3salary = 2500.50
4is_student = True
The code snippet above declares variables of different data types. The age
variable is an integer, the name
variable is a string, the salary
variable is a float, and the is_student
variable is a boolean.
To access the values of these variables, you can simply print them using the print
function:
1print(age)
2print(name)
3print(salary)
4print(is_student)
This will output the values stored in the variables.
In the next lesson, we will explore working with arrays and learn how to handle and perform operations on them in Course course one.
xxxxxxxxxx
if __name__ == "__main__":
# Declare a variable of integer type
age = 25
# Declare a variable of string type
name = "John Doe"
# Declare a variable of float type
salary = 2500.50
# Declare a variable of boolean type
is_student = True
# Print the values of the variables
print(age)
print(name)
print(salary)
print(is_student)