 Photo by Brendan Church on Unsplash

# Booleans

## Numerical values

`>>> print(f"False = {False * 4}\nTrue = {True * 3}") False = 0True = 3`

## Empty vs. Non-Empty

`>>> d = {} >>> d == TrueFalse>>> if d:    # Instead of `if d == True:`...     print('not empty')... else:...     print('empty')empty`
`>>> lt = ['', 'item']>>> lf = []`
`>>> print(f"lt = {'' in lt}\nlf = {'' in lf}\n[] == [''] = {[] == ['']}")lt = Truelf = False[] == [''] = False`
`>>> d = {} >>> print(f"d == True: {d == True}\nall(d): {all(d)}\nany(d): {any(d)}")d == True: Falseall(d): Trueany(d): False>>> d = {''} >>> print(f"d == True: {d == True}\nall(d): {all(d)}\nany(d): {any(d)}")d == True: Falseall(d): Falseany(d): False`

# Strings

## Automatic Concatenation

`>>> 'Hello' 'World''HelloWorld'`
`>>> list('Hello World')['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']`

## `split()`

`>>> print('          Hello    '.split(' ')) ['', '', '', '', '', '', '', '', '', '', 'Hello', '', '', '', '']>>> print(' Hello                     World      '.split())['Hello', 'World']>>> print(''.split(' '))['']>>> print('aaa'.split('a'))['', '', '', '']`

# Integers

## Special Cases

`>>> float('inf') == float('inf')True>>> float('NaN') == float('NaN')False`

## Pre-allocation

`>>> a = 256>>> b = 256>>> a is bTrue>>> a = 257>>> b = 257>>> a is bFalse>>> a, b = 257, 257>>> a is bTrue`
`# Don't use temporary variables when it is not necessary>>> def fibonacci(n):>>>     x = 0>>>     y = 1>>>     for i in range(n):>>>         print(x)>>>         t = y>>>         y = x + y>>>         x = t        # Multi assignment saves the day>>> def fibonacci(n):>>>     x, y = 0, 1>>>     for i in range(n):>>>         print(x)>>>         x, y = y, x + y`

# Tuples

`>>> t = 'item',>>> type(t)tuple>>> t = ('item' 'other_item')>>> print(t)itemother_item`

Data Scientist