Data Types

Types of Data

If you are a Computer Science student you need to know about the different data types that are used in programming.

String – A sequence of alphanumeric characters (e.g. “Hello!” or “Toy Story 3” or “Boeing 747”)

Integer – A whole number (e.g. -120 or 0 or 340)

Float (also called Real) – A decimal number (e.g. -32.12 or 3.14)

Boolean – A logical operation (True or False)

Character – A single alphanumeric character (e.g. “a” or “6” or “?”) [Note: There is no character data type in Python as it would just be a string with a length of 1]


Converting to another Data Type

In Python you can convert a variable from one type to another by overwriting the variable with a different data type (line 2):
screenshot-repl-it-2016-11-05-21-14-38

This converts ghosts from a string (generic expected input data type) to an integer and would output:

screenshot-repl-it-2016-11-05-21-15-01

If you wanted to convert a variable to a string use str() or to a decimal number use float()

Practice Task 1

< Back to Section Three