}
Next Previous Table of Contents

What are Types?

As people, we understand that information does not come in just one form. We recognize that speech, numbers, the written word, music, and images are all different, and we have common ways of creating, sharing, and working with each of these. You don't sing pictures, and you don't paint a novel. (Or at least I don't...)

Computers, at bottom, treat all information the same: everything is either true or false, zero or one. However, because high-level programming languages are written by and for people, we incorporate our own ideas about how information works into the language. In programming, we call these representations "data types," or "types."

When we create or use data, we implicitly tell Python what type of information it is. Python then gets ready to do certain kinds of work with that data, as we'll see.

You should still have the Python REPL open. Enter the following, one after the other:

>>> type("Me. We.")
<class 'str'>
>>> type(True)
<class 'bool'>
>>> type(5)
<class 'int'>
>>> type(5.0)
<class 'float'>
>>> type([1, 2, 3])
<class 'list'>
>>> type({'name': 'patrick', 'profession': 'teacher'})
<class 'dict'>

The types above are strings, booleans, integers, floating point numbers (numbers with decimals), lists, and dictionaries. We'll be working with this set of data types throughout this workshop.

Strings represent textual data, or sequences of arbitrary (from the computer's perspective) characters and symbols. When creating a string, place either single or double quotes around some text. (Don't mix and match the single and double quotes, though.)

>>> "How are you?"
'How are you?'
>>> 'Doing just fine, thanks!'
'Doing just fine, thanks!'

Booleans represent a more philosophical concept: truth and falsity. There are only two booleans, True and `False``. They appear as follows (in title case without quotes):

>>> True
True
>>> False
False

Integers are numbers without a decimal place. Floating point numbers are numbers with a decimal place. While in most cases you can use them interchangeably in Python, it makes sense to keep track of the difference because numbers with decimals present some unique challenges for computers.

>>> 10
10
>>> 10.5
10.5
>>> type(10)
<class 'int'>
>>> type(10.5)
<class 'float'>

Lists are ordered collections of other data types. They begin and end with square brackets, and each individual item in the list is separated by a comma.

>>> [1, 2, 3]
[1, 2, 3]
>>> ['Take out laundry', 'Wash dishes', 'Write Python tutorial']
['Take out laundry', 'Wash dishes', 'Write Python tutorial']
Next Previous Table of Contents