Python Types

A. Numeric

// Booleans
bool_a = True
bool_b = false

// Integer
int_a = 123
int_b = int('123')

// Floats
float_a = 12.3
float_b = float('12.3')

// Complex Numbers
complex_a = -1.23+4.5j
complex_b = complex('-1.23+4.5j')

B. Collections

// Lists (mutable ordered collection of homogenous items)
list_a = []
list_b = ['a', 'b', 'c']
list_c = list('abc')
list_d = list( (1, 2, 3) )

// Tuple (immutable ordered collection of heterogeneous data)
tuple_a = ()
tuple_b = 'a',
tuple_c = ('a',)
tuple_d = 'a', 'b', 'c'
tuple_e = ('a', 'b', 'c')
tuple_f = tuple('abc')
tuple_g = tuple( [1, 2, 3] )
// The parathesis are optional (comma is required)
// unless defining empty tuple or when a comma list means something else (ex: function arguments)

// Range (immutable ordered collection of integers)
range_a = range(0)
// list(var_range) = []
range_b = range(1, 0)
// list(var_range) = []
range_c = range(5)
// list(var_range) = [0, 1, 2, 3, 4]
range_d = range(2, 5)
// list(var_range) = [2, 3, 4, 5, 6]
range_e = range(2, 6, 2)
// list(var_range) = [2, 4, 6, 8, 10, 12]
range_f = range(10, 5, -1)
// list(var_range) = [10, 9, 8, 7, 6]

// Set (mutable unordered collection of DISTINCT hashable data)
set_a = {'a', 'b', 'c'}
set_b = {c for c in 'abracadabra' if c not in 'abc'}
set_c = set()
set_d = set('abc')
set_e = set(['a', 'b', 'c'])

// Frozen Set (immutable unordered collection of DISTINCT hashable data)
frozenset_a = frozenset()
frozenset_b = frozenset('abc')
frozenset_c = frozenset(['a', 'b', 'c'])

// Dict (key-value mapping of hashable keys to data)
dict_a = {'a': 1, 'b': 21, 'c': 52}
dict_b = {1: 'a', 2: 'b', 32: 'c'}
dict_c = {}
dict_d = {x: x ** 2 for x in range(10)}
dict_e = dict()
dict_f = dict([('foo', 100), ('bar', 200)])
dict_g = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
dict_h = dict(a=1, b=21)
dict_i = dict({1: 'a', 2: 'b', 32: 'c'})

print(dict_a['b'])
//> 21

dict_a['b'] = 345
print(dict_a['b'])
//> 345

C. Text Sequences

// Strings/Character Sequences (immutable sequence of Unicode points)
str_a = 'abc'
str_b = "abc"
str_c = '''abc'''
str_d = """abc"""
str_e = """abc
second line"""
str_f = """abc
second line"""
str_g = str(['a', 'b', 'c'])
str_i = str(b'abc')

// Binary Sequences (immutable sequence of single bytes)
binary_a = b'abc'
binary_b = b"abc"
binary_c = b'''abc'''
binary_d = b"""abc"""

// Binary Array (mutable sequence of single bytes)
binaryarr_a = bytearray()
binaryarr_b = bytearray(b'abc')
binaryarr_c = bytearray(10)
binaryarr_d = bytearray(range(20)

D. Other Types

// Module inclusion
import re
from datetime import datetime

// Classes
class Foo:
    def bar(self):
        pass

var_foo = Foo()
var_foo.bar.__func__.whoami = 'my name is bar'
var_foo.bar.whoami

// Null Object
none_var = None

// Ellipsis Object
ellipsis_var = ...