Variables and Data Types

Starter Activity

Complete the Starter Activity in your Notebooks, you have 5 minutes.

Text

Learning Objectives

  1. To fully understand variables and how to refer back to them later in your code

 

2.   To know the differences between data types.                      

 

3.   To understand the difference between assigning data and comparing data 

Variables (Assignment)

A variable is a location of memory where we can store data. 

Any word that comes before a single equals sign becomes a name that will refer to the data that follows. 

L.O. 1: To fully understand variables and how to refer back to them later in your code

Variables (Assignment)

When we reference back to a variable, you must make sure that your spelling and grammar are exactly the same!

 

 

Otherwise, you will get a

SYNTAX ERROR

IF Statements (Comparison)

An IF statement can be used in Python to make a choice and run lines of code based on that choice.

 

However, there are certain rules that must be followed for it to run correctly.

L.O. 3: To understand the difference between assigning data and comparing data

IF Statements (Comparison)

Rule 1

For a comparison to be made, we must use two operator signs:

 

"==" - is equal to

"!="  - is not equal to

">=" - is greater than or equal to

"<=" - is less than or equal to

IF Statements (Comparison)

Rule 2

Any comparison must finish the line with a colon ":"

 

Otherwise, you will get a

SYNTAX ERROR

IF Statements (Comparison)

Rule 3

A string can only be compared to another string.

It CANNOT be compared to an integer or boolean!

 

In the same way an integer can only be compared to an integer and a float can only be compared to a float. 

L.O. 2: To know the differences between data types.  

Also, mathematical operators can only be applied to an integer/float and NOT a string!

Activity

Log into Grok Learning and continue your work on Python for Beginners

Plenary

Complete the quiz in your Notebooks