Computer Science LearnITWithMrC ⛯ Year 7 Year 8 Year 9 GCSE
Responsive image

Lesson Video


Lesson Tasks

  • Watch the Lesson video
    Make notes on your notes sheet.
  • Read the lesson notes
    Make notes on your notes sheet.
  • Complete the learning activities
    Make any notes on your notes sheet.
  • Check the Learning outcomes
    Update your learning objectives

What do I need to Learn?

I need to learn how to understand and know how to use in variable declaration in a computer program.
I need to learn how to understand and know how to use constant declaration in a computer program.
I need to learn how to understand and know how to use assignment in a computer program.
I need to learn how to use meaningful identifier names and know why it is important to use them.

Key Terms

High level languages Assignment operator Assigned value Snake case Camel case Variable Constant

Python Variables

A variable is a location in memory used to store some data (value).

They are given unique names to differentiate between different memory locations. The rules for writing a variable name is same as the rules for writing identifiers in Python.

We don't need to declare a variable before using it. In Python, we simply assign a value to a variable and it will exist. We don't even have to declare the type of the variable. This is handled internally according to the type of value we assign to the variable

Variable assignment - Assigning value to a Variable in Python

We use the assignment operator (=) to assign values to a variable. Any type of value can be assigned to any valid variable.

Assignment Example

a = 7
b = 3.14
c = "Hello World"

Click on the run button below to see the output of the python code assigning variables

See if you can improve the output of the code above?

Data types in Python

Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

There are various data types in Python. Some of the important types are listed below.

Python Numbers

Integers, floating point numbers and complex numbers falls under Python numbers category. They are defined as int, float and complex class in Python.

We can use the type() function to know which class a variable or a value belongs to.

Type Example

a = 7
print(a, "is of type", type(a))
b = 3.14
print(b, "is of type", type(b))
c = "Hello World"
print(c, "is of type", type(c))

Python Activity

  • Open up python IDLE and create a new file called variables
  • Declare three variables each of a different data type
  • Show what the data types are using the type() function
  • Try and add 3 variables together and print out the result
  • Click here if you need help ▶

    Extension Activity Using Java

    Click on the buttons below to see how variables and data types are used in Java

    Java Tutorial Java Compiler

    Update your objectives