Python - Overview
Why Python
- Easy to learn.
- Available everywhere: Linux, macOS, Windows.
- Super popular in machine learning / data science, competing with R.
help()
gets docstring for any module / method / function.- Simple, compact and powerful.
- list comprehensions.
- class magic methods.
- very powerful OOP.
- built-in strings and array slicing.
- huge and coherent standard library.
Ecosystem
- Tensorflow / PyTorch: machine learning frameworks.
- Scikit Learn: ML.
- pandas: data analysis and manipulation. https://pandas.pydata.org/
- numpy: scientific computing. https://numpy.org/
- jupyter: notebook. https://jupyter.org/
- Django: web framework.
- Tornado: a Python web framework and asynchronous networking library. https://www.tornadoweb.org/
- Twisted: An event-driven networking engine. https://twisted.org/
- Pillow: For image processing
Python specific features
Swap
a, b = b, a
If You Forget Function Name
Use dir()
to check the function names:
>>> dir([])
[... 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
Or pretty print:
>>> import pprint; pprint.pprint(dir([]))
[ ...
'append',
'clear',
'copy',
'count',
'extend',
'index',
'insert',
'pop',
'remove',
'reverse',
'sort']
All and ANY
ALL: if every one is truthy
>>> all([1, "abc", [False]])
True
>>> all([1, 0, 1])
False
ANY: if any one is truthy
>>> any([1, 0, 0])
True
>>> any(["", 0, 0])
False
Resources
- functional programming
- performance
- best practice