Python Programming Language Cheat Sheet: 2022 Guide

With over 10.1 million developers using Python, the popularity of the Python programming language cannot be denied. Since the first release in 1990, Python has gained public support in universities and businesses, being widely used in artificial intelligence and machine learning, serving as the foundation for OpenStack, as well as the file storage service in the Dropbox cloud.

This extensibility makes Python a great programming language for junior developers, but also one that remains widely applicable, as Python is widely used for real-world applications. This cheat sheet explores what Python is for and how it compares to other programming languages, and provides resources for learning the language. This article is also available for download: Python Programming Language: A Cheat Sheet (free PDF).

SEE: Recruitment Kit: Python Developer (TechRepublic Premium)

What is the Python programming language and who created it?

Python is an interpreted programming language (also known as 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 ​​because it prioritizes code readability and white space usage over compact and tiny source files.

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

SEE: Python Eats the World: How One Developer’s Side Project Became the Most Popular Programming Language on the Planet (TechRepublic PDF cover story)

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

What is Python for?

Python’s design as a language makes it a good choice for projects with multiple authors, as the language’s inherent readability helps to grasp code and clearly understand how it works. Python is a powerful programming language, allowing even novice developers to accomplish a great deal – as with virtually everything in computing, there’s an xkcd for that.

Python is currently one of the most popular programming languages ​​to learn, widely sought after for its machine learning (ML) and data science attributes. The language’s scikit-learn ML library saw usage increase by 11% in 2020, while the PyTorch ML framework used for deep learning grew by 159%. Python is also Microsoft’s most popular extension for Visual Studio Code, with support on Azure and an easy install option from the Windows Store.

Python is widely used in artificial intelligence; Google’s TensorFlow framework includes Python modules, as do Keras and Scikit-learn. Similarly, Facebook’s PyTorch is growing in popularity, with support on AWS and Azure. For data scientists wishing to prepare data for machine learning, the The Anaconda project is a distribution of Python and R it’s optimized for scientific computing, with an emphasis on numerical methods and statistical analysis. IBM’s Qiskit and D-Wave’s Ocean learning platforms also use Python to program quantum computers. Other science-based options include the popular NumPy, SciPy, and Matplotlib libraries.

Outside of scientific computing, Python remains popular for web development frameworks including Django, CherryPy, Pyramid, Flash, web2py, and webapp2. Graphics editing programs also use online Python scripting, including Autodesk 3ds Max, Maya, and MotionBuilder 3D animation software, as well as Cinema 4D, Lightwave, Houdini, and modo, Nuke Compositor, and Toolset. open source Blender. It is also used in colloquial 2D graphics software, As PaintShop Pro, as well as open source software GIMP, Inkscape and Scribus.

Additionally, LibreOffice uses Python for inline scripting, similar to how Visual Basic is used to extend Microsoft Office functionality.

SEE: All of TechRepublic’s Smart Person’s Cheat Sheets and Guides

Why use Python rather than other languages?

In 1999, software developer Tim Peters, a major Python contributor 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 the 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 matters.
Special cases are not special enough to break the rules.
Although practicality outweighs purity.
Mistakes should never pass in silence.
Unless they are explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one (and preferably only one) obvious way to do this.
Although it might not be obvious at first unless you are Dutch.
It’s better now than ever.
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 can be a good idea.
Namespaces are a great idea, let’s do more!

How does Python compare to other programming languages?

Python can be used for virtually any use case that any other high-level language (C/C++, JavaScript, PHP, etc.) can be used for. Its flexibility makes it a popular tool for prototyping, especially when used with a UI toolkit. Implementations for modern microcontrollers exist, with a focus on 32-bit and higher instruction sets.

While the CPython reference implementation is largely useful for most use cases, other Python interpreters exist to meet specific needs and deployment scenarios. MicroPython is a microcontroller-centric implementation supporting Arm architectures, in addition to Arduino, ESP8266, ESP32, and RISC-V (32 and 64-bit) architectures. with a Raspberry Pi implementation for its Pico family of microcontroller boards and RP2040 chips. 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 just-in-time (faster) compiler, while CPython is an interpreter.

Python 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.

While Python normally runs using an interpreter, there are tools that allow you to compile to other languages ​​and machine code. These include a JavaScript transpiler, C and C++ compilers. Helpfully, these approaches allow you to take Python code and use it as libraries and modules to use with code written in other languages.

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

Image: James Sanders/TechRepublic

What version of Python should I use?

The Python 3.x series was introduced in December 2008, patching and fixing fundamental design flaws, as well as general modernization of the language. Python 3 was developed with the guiding principle of “[reducing] duplication functionality by removing old ways of doing things. For this reason, Python 3 is not fully backwards 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 versions of Python are 3.8.13, 3.9.13, and 3.10.5.

Python 3.11 is currently in beta, with beta 3 released in early June 2022, and expected to be released in October 2022. Speeding up Python is one of the primary goals of the core language 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. Python 3.11 should be supported until the end of 2027.

How to learn programming in Python?

Learning Python doesn’t require getting a computer science degree – there are loads of resources available online to help people get started with the programming language.

Google has launched Python training, 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 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, including Atom, PyCharm, Geany, Sublime Text, and Visual Studio Code. Perhaps the most popular Python programming tool for beginners is cross-platform Thonny which also supports dialects like MicroPython.

Many offer REPL (Read Evaluate Print Loop) tools to help you try out new Python commands in your editor or browser. This approach also makes it easier to test new code as you write it, without leaving your chosen development environment. Other tools, like Jupyter Notebooks, embed a Python interpreter in a shareable document. This allows you to share code with colleagues or provide an experiment-ready interactive environment to experiment with machine learning or numerical analysis.

Comments are closed.