Types

https://docs.python.org/3/library/index.html

INTRODUCTION

There are three basic sequence types: lists, tuples, and range objects.

Binary sequence types: bytes, bytearray, memoryview.

There are operations supported by most sequence types, both mutable and immutable.

BUILTIN TYPES

+-----------+-----------------+----------------------+
| Name      | Type            | Properties           |
+-----------+-----------------+----------------------+
| numbers   | Numeric         | immutable, hashable  |
| range     | Number Sequence | immutable, hashable  |
| strings   | Text Sequence   | immutable, hashable  |
| bytes     | Binary Sequence | immutable, hashable  |
| bytearray | Binary Sequence | mutable              |
| list      | Sequence        | mutable              |
| tuple     | Sequence        | immutable, hashable  |
| dict      | Mapping         | mutable              |
| file      | Extension       | iterable (txt)       |
| set       | Set             | mutable              |
| frozenset | Set             | immutable, hashable  |
+-----------+-----------------+----------------------+

TESTING TYPES


# isinstance(obj, class_or_tuple) return bool

isinstance(x, (int, float))
isinstance(D, dict)
isinstance(L, (list, tuple))
isinstance(S, (set, frozenset))

help(type_name)

# type(object) returns the object's type
# type(name, bases, dict) returns a new type

type(1)   # <class 'int'>
assert type(1) == int
type(1.2)   # <class 'float'>
assert type(1.2) == float
type([])   # <class 'list'>
type({})   # <class 'dict'>