WeLearn

Grade 11 Information Technology · Lesson 6.3

Variables and Data Types

Unit 6: Fundamentals of Programming

A variable is a named storage location in memory that holds a value which can change while the program runs. In Python you create a variable by assigning a value with the = sign, for example age = 16. The = sign means 'store the value on the right in the name on the left', not mathematical equality. A variable can later be given a new value: age = age + 1 makes it 17.

Key terms

Variable
named memory location holding a value
Assignment
storing a value in a variable with =
int
whole-number type
float
decimal-number type
str
text (string) type
bool
True or False type
Type conversion
changing a value from one type to another
Keyword
reserved word that cannot be a variable name
All Grade 11 Information Technology key terms →

Summary

  • Variables store values that can change; = means assignment.
  • Names start with a letter or underscore and cannot be keywords.
  • Basic types: int, float, str, bool.
  • input() returns str; convert with int() or float() before calculating.

In everyday life: A shop-keeping program in Birr would store item names as str, quantities as int and prices such as 45.50 as float.

Check yourself

  • What does = mean in Python?
  • Give two rules for naming variables.
  • What type is "25"?
  • Why is int() often used with input()?

Practice questions

  1. 1. What is the data type of the value 3.5 in Python?

    • A. int
    • B. str
    • C. float
    • D. bool
    Show answer

    Answer: float

    Numbers with a decimal point are floats; whole numbers are int.

  2. 2. True or false: In Python, a variable name may start with a digit, e.g. 2price.

    Show answer

    Answer: False

    Variable names must start with a letter or underscore; they may contain digits after the first character.

On WeLearn

The full lesson: reading notes, worked examples, class activities and the Unit 6 quiz

Study Variables and Data Types on WeLearn

Teach Variables and Data Types with WeLearn

We will bring a demo to your school: a lesson on your interactive TV, a virtual lab and a classroom game, with your own teachers.