Python is a general-purpose programming language.
It has a large standard library (“batteries included”) and 3rd party libraries are distributed through the Python Package Index (PyPi).
Python 3 introduced a number of backwards incompatible changes, which can be confusing. When learning the language, make sure that the resources you use cover the same version you are using (2.7 or 3.x).
Working with Python Projects
pip is python’s package manager (similar to
gem in ruby-land and
npm for node.js). The convention is to list dependencies in a
By default libraries will be installed for the system python, which may require superuser access.
Instead, you can use
virtualenv, which provides an isolated python environment for your project.
$ virtualenv env # Create a virtualenv directory, 'env' $ source env/bin/activate # Activate the virtualenv (env)$ pip install -r requirements.txt # Install project dependencies
Python Test Frameworks
Python comes with a built in test framework, unittest.
- PyCharm is a python-focused IDE from Jetbrains
- Virtualenvwrapper is an easier way of working with virtualenvs
- Visual Studio Code for a fast lightweight IDE, python plugins available
- The State of Python (2 vs 3)
- Properly Installing Python
- Python Koans teaches Python in bitesize chunks using TDD
- Learn Python The Hard Way (for people new to programming)
- Python Programming FAQ
- Writing Great Python Code
- Beyond PEP 8 – Best practices for beautiful intelligible code (PyCon 2015)
- Learning Python on the move in bitesized chunks via mobile apps
- Plural Sight video tutorials (requires subscription)
Writing idiomatic Python
The Zen of Python
$ python Python 2.7.3 (default, Feb 18 2013, 13:30:57) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.24)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
The authoritative style guide for python is PEP8.