Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.

Python programming language: A cheat sheet

This guide explores what Python is used for, how it compares to other programming languages, and developer resources for building skills in Python.

Python is eating the world: How one developer's side project became the hottest programming language

With over 10.1 million developers using Python, the popularity of the Python programming language can't be denied. Since the first release in 1990, Python has gained public support in academia and business, being used extensively in artificial intelligence and machine learning, serving as the underpinning of OpenStack, as well as powering the cloud file storage service Dropbox.

This extensibility makes Python an excellent programming language for junior developers to get started with, but also one that remains applicable at scale, as Python is used extensively for real-world applications. This cheat sheet explores what Python is used for and how it compares to other programming languages, and provides resources for learning the language. This article is also available as a download: Python programming language: A cheat sheet (free PDF).

SEE: Hiring kit: Python developer (TechRepublic Premium)

What is the Python programming language?

Python is an interpreted programming language (also called a scripting language), created in 1990 by Dutch programmer Guido van Rossum, following his experience working on the education-focused ABC language at CWI. Python differs from other programming languages, as it prioritizes code readability and use of whitespace over compact, tiny source files.

Python is dynamically typed and garbage-collected (through reference counting and cycle detection), supports object-oriented and structured programming fully, and largely supports functional and aspect-oriented programming, making it particularly versatile and applicable for a wide variety of use cases.

SEE: Python is eating the world: How one developer's side project became the hottest programming language on the planet (TechRepublic cover story PDF)

The standard library is commonly considered one of the greatest strengths of Python; this feature enables programmers to quickly develop projects without needing to rely heavily on third-party packages for the basic plumbing of a given application. To complement the standard library, the Python Package Index (PyPI) catalogues over 300,000 packages that provide various functions.

Additional resources

What makes Python a good choice for my project?

Python's design as a language makes it a good choice for projects with multiple authors, as the inherent readability of the language aids in the ability to pick up code and clearly understand how it operates. Python is a powerful programming language, enabling even junior developers to accomplish quite a lot—as is the case for practically everything in computer science, there is an xkcd for that

Python is currently one of the most popular programming languages for people to learn, widely desired for its machine learning (ML) and data science attributes. The language's scikit-learn ML library saw an 11% increase in use in 2020, while the PyTorch ML framework used for deep learning jumped in use by 159%. Python is also Microsoft's most popular extension for Visual Studio Code.

Python is used extensively in artificial intelligence; Google's TensorFlow framework includes Python modules, as does Keras and Scikit-learn. The Anaconda project is a distribution of Python and R for scientific computing. IBM's Qiskit and D-Wave's Ocean learning platforms also use Python for programming quantum computers. Python is used by data scientists, with popular libraries including NumPy, SciPy, and Matplotlib, and in web development frameworks including Django, CherryPy, Pyramid, Flash, web2py, and webapp2.

Graphics editing programs also use inline Python scripting, including the 3D animation software Autodesk 3ds Max, Maya, and MotionBuilder, as well as Cinema 4D, Lightwave, Houdini, and modo, the Nuke compositor, and the open-source Blender toolset. Of 2D graphics software, PaintShop Pro, as well as the open-source software GIMP, Inkscape, and Scribus.

Additionally, LibreOffice uses Python for inline scripting, much in the same way Visual Basic is used to extend features of Microsoft Office. 

SEE: All of TechRepublic's cheat sheets and smart person's guides

In 1999, software developer Tim Peters, a major contributor to Python and creator of the original CPython implementation, wrote the "Zen of Python," an explanation of Python's design philosophy, and the philosophy that programmers should incorporate into their programming approach. The document was later incorporated into official Python documentation.

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!

Additional resources

How does Python compare to other programming languages?

Python can be used for practically any use case that any other high-level language (C/C++, JavaScript, PHP, etc.) can be used for. Implementations for modern microcontrollers exist, though older CPUs (m68k, z80, 6502) cannot use Python.

While the CPython reference implementation is broadly useful for most use cases, other Python interpreters do exist to address specific needs and deployment scenarios. MicroPython is a microcontroller-focused implementation supporting Arm architectures, in addition to Arduino, ESP8266, ESP32, and RISC-V (32- and 64-bit) architectures. CircuitPython is an education-focused fork of MicroPython.

PyPy is the most popular general-purpose alternative implementation of Python. It differs from CPython in that PyPy is a (faster) just-in-time compiler, while CPython is an interpreter. 

Pyston is another alternative implementation of Python. Pyston 2.2, an open-source implementation of Python 3.8.8, promises to be 30% faster than the original implementation. The Pyston fork of CPython 3.8.8 is available on GitHub.

ENTERPRISE SOFTWARE

Other language-target implementations also exist, including CLPython for Common Lisp, IronPython for .NET/Mono, and Jython for Java. Likewise, the Nuitka project is a source-to-source compiler from Python to C/C++ source code.

Additional resources

What is the difference between Python 2 and Python 3?

The Python 3.x series was introduced in December 2008, addressing and rectifying fundamental design flaws, as well as generally modernizing the language. Python 3 was developed with the guiding principle of "[reducing] feature duplication by removing old ways of doing things." Due to this, Python 3 is not fully backward-compatible with Python 2, requiring developers to modernize their code to run on the new version. 

Support for Python 2.7 ended on January 1, 2020. The latest releases of Python are versions 3.8.10, 3.9.5, and 3.10.0b2. Python 3.10.0b2 is the second of four planned beta release previews for Python 3.10, which is expected in August 2021.

With Python 3.10 moving to beta, development has now started on Python 3.11, which is due to be released in October 2022. Speeding up Python is a primary focus of the language's core development team, with van Rossum hoping to double the performance of CPython in version 3.11 as part of his work on Microsoft's Developer Division.

Additional resources

How do I get started programming in Python?

Learning Python doesn't require getting a degree in computer science—there's a wealth of resources available online to help users get started with the programming language.

Google launched a Python training course, the Google IT Automation with Python Professional Certificate, on Coursera. 

SEE: Getting started with Python: A list of free resources (free PDF) (TechRepublic)

TechRepublic Academy, a joint venture between TechRepublic, ZDNet, and StackCommerce, also offers a wide variety of in-depth Python training courses.
 
If you're already familiar with programming, chances are your IDE of choice either natively supports Python or support can be added using a plugin. For new programmers, using a free IDE that supports Python is a quick way to get started—these include Atom, PyCharm, Geany, Sublime Text, and Visual Studio Code. 

Additional resources

Binary Code Vector Texture

Image: James Sanders/TechRepublic