Fundamental types in Python

Download original file: 2_fundamental_python_types.ipynb

View original file in nbviewer: 2_fundamental_python_types.ipynb

Fundamental Python types

Python has a number of fundamental types. Please explore the code below to see what they are.

a = 1; b = 10000000000000000000000000
type(a), type(b)


c = 1.0
type(c)

The boolean type can contain the values True and False which always

start with capital letters:

d1 = True
d2 = False

type(d1)

Complex numbers are a fundamental type: note the use of j to specify the

imaginary part

e = 1.0 - 1.0j
type(e)

The None type

This type is very commonly used and also starts with a capital N.

f = None

All types have properties

The variable c defined above is an integer type. This type has the following properties that are accessed with dot notation. The dot can be thought of as meaning “get something from the thing on the left” (in this case c).

c.bit_length    c.conjugate    c.denominator    c.imag    c.numerator

c.real

In this case c.bit_length is actually a function which must be called using round brackets ()to use (more on functions later).

c.real, c.bit_length()

Some properties are hidden

Although f is a None type, it still has hidden properties.

f.__sizeof__()

Many types have common properties

Python has been designed such that its types are as compatible as possible with each other. This is done by giving them common properties so that the same Python code is able to process different types.

Exercise: Find the common properties between the types listed above