In Python, variables are used to store and manipulate data. They act as containers for holding values. Python supports different data types, such as integers, floats, strings, and booleans.

Let’s start by learning how to declare variables and work with different data types:

# Declaring variables
name = "Alice"
age = 25
height = 1.65
is_student = True

# Printing variable values
print("Name:", name)
print("Age:", age)
print("Height:", height)
print("Is Student?", is_student)

Explanation:

  • We declare variables name, age, height, and is_student to store different types of data.
  • The variable name is assigned a string value “Alice”, age is assigned an integer value 25, height is assigned a float value 1.65, and is_student is assigned a boolean value True.
  • We use the print() function to display the values of the variables on the screen.

Now it’s time for a practical task:

Task 2:

Write a Python program that declares variables for your name, age, and favorite color. Print out the values of these variables on separate lines.

Solution:

Spoiler warning

    name = "CryptoPensioner"
    age = 99
    favorite_color = "black"

    print(f"My name: ",name)
    print(f"Age: ",age)
    print(f"My favourite color is: ",favorite_color)

Once you’ve completed the task, you can proceed to the next lesson.