Learn about Python, the popular and pervasive programming language built for nearly every purpose.
Python is a popular general-purpose programming language that can be used for a wide variety of applications. It includes high-level data structures, dynamic typing, dynamic binding, and many more features that make it as useful for complex application development as it is for scripting or "glue code" that connects components together. It can also be extended to make system calls to almost all operating systems and to run code written in C or C++. Due to its ubiquity and ability to run on nearly every system architecture, Python is a universal language found in a variety of different applications.
Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. —Python Software Foundation FAQ
The programming language includes thousands of third-party modules available in the Python Package Index (PyPI). PyPI provides popular standards for different expertise, like Django for web development and NumPy, Pandas, and Mathplotlib for data science.
First developed in the late 1980s by Guido van Rossum, Python has advanced as an open source programming language by managing public discussion through Python Enhancement Proposals (PEPs). In 2018, van Rossum stepped down as the language's Benevolent Dictator For Life (BDFL), and, as officially outlined in PEP 13, a steering council was put in place to serve as the leadership of the language.
The Python Software Foundation (PSF) is a 501(c)(3) non-profit corporation that holds the intellectual property rights behind the Python programming language. This includes Python version 2.1 and later, PyPI, the CPython reference implementation, and infrastructure to maintain the language. The PSF also provides grants for software craftship and runs multiple PyCon conferences a year.
Python is currently on its third major version and is regularly updated.
Is Python open source?
Yes, all modern versions of Python are copyrighted under a GPL-compatible license certified by the Open Source Initiative. The Python logo is trademarked but allows for customization (see the full license for details).
You can download the Python source code here.
Why use Python?
There are several reasons why Python is a good choice as a programming language, depending on your perspective and background.
Python for programmers
Those new to programming can benefit from Python's high level of abstraction. It is highly interactive and known for its "strong opinions" around specific syntax (including whitespace). Python, like other high-level languages, has a garbage collection process to manage memory or delete unused resources. A user can receive instant feedback from the interpreter by typing python on the command line or by using projects like JupyterLab if they want a browser-based development experience. Many users also appreciate that Python has a strict syntax enforced by the compiler, making it easy to have a single "right way" to write a program. That style of development is reinforced through The Zen of Python:
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.
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!
Regardless of their experience level, programmers from a number of different backgrounds contribute to the language in significant ways. Python has a mature ecosystem of both free and proprietary tools, including integrated development environments (IDEs), linters, and frameworks. Modules shared through PyPI and Conda have a depth and breadth that will cover nearly every topic. Some of the most popular include:
- Web frameworks such as Django, Pyramid, Flask, and Bottle.
- Internet protocol support in the standard library for JSON, HTML, XML, FTP, IMAP, and sockets.
- Data science and machine learning with SciPy, Pandas, IPython, NumPy, and more.
Python for sysadmins
If you are a sysadmin, you may be familiar and comfortable with shell scripting for system administration. Bash and other shells are powerful functional languages, but Python is object-oriented, with thousands of libraries that you can use in your own work. In fact, many open source and proprietary IT infrastructure components provide Python libraries so you can automate them, making it a more maintainable language for sysadmins, site reliability engineers (SREs), and IT operators.
The Python community
Perhaps most importantly, Python has an enormous user community. Python's popularity is both a cause and an effect of its community. It was the #1 programming language in 2018, according to the IEEE Spectrum ranking, and it is the #1 "Most Wanted" and #2 "Most Loved" language, according to StackOverflow's 2019 Developer Survey. Pythonistas, as members of the community call themselves, meet around the world in thousands at PyCon conferences.
This means that no matter what problem you're trying to solve, chances are there are already strong people working on a solution. Chances are also good that they have shared code, documentation, tutorials, and examples to help program a solution in Python. There are numerous IDEs and other development tools to choose from, and thousands of open source packages available to extend Python to do just about anything you can think of.
5 surprising things you can do with Python
Python is so versatile that it can be used to power complex applications stacks, simplify infrastructure testing, and do everything in between. Here are a few examples to get you started:
- Create a videogame with Python
- Add methods to libraries retroactively with singledispatch
- Create interactive data science tutorials with Jupyter Notebooks
- Write tests to verify IT infrastructure state
- Write both Python and C with Cython
Who uses Python?
Many organizations are Python users. Some of the most vocal and best-known Python-using companies include:
- Mozilla, best known for Firefox, says it has over "230k lines of code" written in Python.
- Google shares its internal Python training.
- Microsoft promotes Python development with its IDE, Visual Studio Code.
- Netflix shares its extensive use of Python for everything from regional failover monitoring software to data science.
- Uber says it uses Jupyter Notebook and IPython to share data.
- Reddit is largely written in Python and shares the source code on GitHub.
- Dropbox has been a public advocate for Python 3 in its infrastructure.
- Slack, Digital Ocean, Lyft, Sauce Labs, and Fastly all mention using Python in an Increment article.
- Many financial firms, such as CapitalOne, Bloomberg, and JPMorgan, recruit Python developers.
In addition, many IT infrastructure technologies are written in Python. It is the primary language used for the massive cloud computing project OpenStack, which is powering private and public clouds in data centers all over the world. Infrastructure automation software Ansible is written in Python as well.
It's also used to write desktop software, such as Calibre and OpenShot. Blender is among the many applications written in other languages that allow users to script in Python. It's also a popular language for machine learning and scientific, statistical, mathematical, and other types of specialized computing. Even the Raspberry Pi gained its name from the founders' plan to use the platform for teaching Python.
So, in short, what is Python used for? Nearly everything!
Where can I learn Python?
There is an abundance to learn about Python and a lot of resources available to do so. Think about balancing your input from resources and your output of practicing writing the language.
Start by understanding how to install Python and choosing a text editor or IDE to write the code.
- Cheat sheet: Python 3.7 for beginners
- How to install Python on Linux and Windows
- How to (correctly) run Python on MacOS
- Top 3 open source Python IDEs
Choose a project that inspires you, and begin to master the libraries that will power you to complete your project.
- 7 essential PyPI libraries and how to use them
- 8 great Python libraries for side projects
- How to create a 2D game with Python
- Getting started with Python for data science
Continue to hone your expertise through debugging, sharing code, and tests.
- 7 steps for hunting down Python code bugs
- How to open source your Python library
- Automate your Python code tests
Share with us
No matter what level of Python expertise you have, share your knowledge by writing for us on Opensource.com. It will help make you and our readers better programmers.
And be sure to follow our Python tag and be on the lookout for more Python articles on Opensource.com.