Programming · StudentHub Lesson

Variables & Data Types

Learn how programs store data in variables using types like integers, strings, and booleans.

18 minBeginner
01

What you will learn

  • Define what a variable is
  • Identify common data types
  • Declare and assign variables in Python
  • Distinguish between integers, floats, strings, and booleans
  • Understand type conversion basics
02

Watch the lesson

Python for Beginners – Full Course [Programming Tutorial] · freeCodeCamp.org

Watch on YouTube
03

Topic notes

Main Idea

Variables are named storage locations in a program that hold data, and each variable has a data type describing what kind of value it stores.

Key Concepts

  • Variables can be created and reassigned during a program
  • Common data types: integer, float, string, boolean
  • Python is dynamically typed, so you don't declare types explicitly
  • Type conversion changes data from one type to another

Definitions

  • Variable: a named container for storing data values
  • Data type: a classification of what kind of value a variable holds
  • Boolean: a data type with only True or False values

Syntax

```python

age = 15 # integer

height = 5.6 # float

name = "Alex" # string

is_student = True # boolean

```

Examples

  • score = 100 creates an integer variable
  • str(100) converts the integer 100 to the string "100"

Common Mistakes

  • Forgetting quotes around strings
  • Mixing types without converting (e.g., adding a string and an integer)
04

Key concepts

Variable declarationInteger, float, string, boolean typesDynamic typing in PythonType conversion
05

Important terms

Variable
A named container that stores a data value
Data type
The category of value a variable can hold, e.g., integer or string
Type conversion
Changing a value from one data type to another
06

Worked examples

Problem

Create a variable storing your age and print it

  1. 1. age = 15
  2. 2. print(age)

Answer: 15

07

Quick revision

  • Variables store data with names
  • Python infers type automatically
  • Common types: int, float, str, bool
  • Use type() to check a variable's type
  • Convert types using int(), str(), float()
08

Check your understanding

Question 1 · Multiple choice

Which of these is a valid Python string assignment?

Question 2 · Multiple choice

What data type is the value True?

Question 3 · True or false

In Python, you must declare a variable's type before using it.

Question 4 · Short answer

What function converts a string to an integer in Python?

Question 5 · Short answer

What is stored in the variable x after x = 3.14?

Done with Variables & Data Types?

Sign in to save your progress across the library.