Numbers, booleans and dynamic typing in Python

Introduction

Introduction

ints and floats

complex

type checking. na checking

define as specific data type in python. long int etc

null/na etc in python. nan. inf

overflows of int etc size in python what happens if number gets too big?

Arithmetic

// in python is integer point division. / is floating point division

References and copying on write


a = 1000
b = a

This gives \(b\) the same address as \(a\).

If we instead do the following then \(b\) will have a different reference after it is changed.

a = 1000
b = a
b = b + 1

Small integer caching

Everything in Python is an object.

Normally, when a number is referenced an object for it is created.

If the number is a small integer (between \(-5\) and \(256\) inclusive) instead a reference to these objects are used.

Casting

Booleans

Dynamic typing and lack of generics

Don’t need generics because of dynamic typing.

Uses ducktyping.

Type hints

x: int = 1
y: float = 2