Data Types

Strings

“Bob”   “Passsword@123”

Strings are used to store a mixture of alphanumerical characters, or other characters, such as . , @:()  etc.

Data that might be stored as a string include:

  • Names
  • Passwords
  • Telephone numbers (because they don’t just contain numbers…)
  • Sentences / paragraphs

Most input functions store inputs as text  by default, so if they need to stored in an alternative data type they need to be cast or reassigned.

Integers

5           200          -75        73000000000

Integers are positive or negative whole numbers

Data the might be stored in integers include:

  • Age
  • Weight( in whole kgs)
  • Temperatures
  • Currency amounts (e.g. pence)

Floats / Real

4.234543                -41.00                        43.719

Floats (or Reals) are positive or negative numbers that include a decimal place.

They can be used to store values where a decimal place is needed.

  • Currency in pounds E.g. 4.25
  • Precise measurements in meters 4.25m
  • Temperatures with decimal places

Booelans

True           False

Booleans are used to store True / False values

Any data where a True or False  value is appropriate:

  • Is a member of a club?
  • Is the person coming?

Char

M                F

A char is used where there are a limited number of possibilities, but too many to use a Boolean. Chars use up less space than strings because only one value is stored.

For instance:

  • Infant, Child or Adult can be stored under  I/C/A
  • Gender types male,female,other   M/F/O

 

Type Casting

print(“You are ” + str(age) + ” years old”)

Often a variable is stored as one type but is sometimes needed to be represented temporarily as another type. In this instance variable casting needs to be used. The blue text shows the casting tasking place.

Example

Here an integer has been stored, but needs to be concatenated with 2 strings. It needs to be cast first

price = 5.23

print("The total cost of you shopping is £" + str(price) + ". Thankyou")

Other Resources

BBC Data Types Quiz

Python Data Types Quiz

Kahoot

(Replace with better kahoot with more questions)