<Python tools> data types (part 1/2)

Queenie Peng
2 min readJun 11, 2021

Topic 2: three data types — Dictionary, Numeric and Boolean

Learning through topic 1, we know how to use Python as a calculator and to assign variables. Now let’s dig into built-in data types in Python!

In topic 2, we introduce three data types: Dictionary, Numeric and Boolean

Following are the built-in data types in Python:

Numeric data type:

1. Integer (int)

Int contains positive or negative whole number.

2. Float

Float contains real numbers with decimal point.

3. Complex

Complex contains (real number) + (imagine number)

Boolean (bool)

Boolean values used in Python come up with two outcomes: True or False.

(Caution! True and False with capital ‘T’ and ‘F’ are valid booleans otherwise python will throw an error.)
(Caution! True and False with capital ‘T’ and ‘F’ are valid booleans otherwise python will throw an error.)

Boolean is often used to show a result after running the codes. b==cis a way to calculate wether b equals c.

b is 2, and c is 3, so that b does not equal c. The boolean value of is b==cFalse.

Dictionary (dict)

A dictionary is a set of key: value pairs. A pair of braces creates an empty dictionary: {}. We build a dictionary like this: {key: value}

Main function of a dictionary: storing values with keys.

The example below creates a dictionary, using country codes as keys.

If we want the keys sorted, we can use sorted()

Upcoming in Topic 3 :

we will introduce Sequence and Set.

--

--