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)
- We declare variables
is_studentto store different types of data.
- The variable
nameis assigned a string value “Alice”,
ageis assigned an integer value 25,
heightis assigned a float value 1.65, and
is_studentis 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:
Write a Python program that declares variables for your name, age, and favorite color. Print out the values of these variables on separate lines.
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.