Python tutorials

Not just NVIDIA: GPU programming that runs everywhere

If you’re doing computations on a GPU, NVIDIA is the default, alongside its CUDA libraries. Some libraries like PyTorch support do support AMD GPUs and Macs. But from the re-implementations of NumPy, SciPy, and Pandas in the RAPIDS project, to Numba’s GPU support, NVIDIA has best software support in the Python world. Sticking to NVIDIA-specific software has some downsides, however: It won’t run on modern Mac laptops. Testing in CI is more difficult: you need custom runners that have NVIDIA […]

Read more

BNF Notation: Dive Deeper Into Python’s Grammar

While reading the Python documentation, you may have found fragments of BNF notation (Backus–Naur form) that look something like the following: What’s the meaning of all this strange code? How can this help you in understanding Python concepts? How can you read and interpret this notation? In this tutorial, you’ll get to know the basics of Python’s BNF notation and learn how to take advantage of it to get a deep understanding of the language’s syntax and grammar. To get […]

Read more

Create Conway’s Game of Life With Python

Wouldn’t it be cool to build a Python game that only requires initial user input and then seems to take on a mind of its own, creating mesmerizing patterns along the way? You can do exactly that with Conway’s Game of Life, which is about the evolution of cells in a life grid. Implementing the Game of Life algorithm is a good exercise with many interesting challenges that you’ll have to figure out. Specifically, you’ll need to build the life […]

Read more

Primer on Python Decorators

In this tutorial on Python decorators, you’ll learn what they are and how to create and use them. Decorators provide a simple syntax for calling higher-order functions. By definition, a decorator is a function that takes another function and extends the behavior of the latter function without explicitly modifying it. This sounds confusing, but it’ll make more sense after you’ve seen a few examples of how decorators work. You can find all the examples from this tutorial by downloading the […]

Read more

How to Write Beautiful Python Code With PEP 8

PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Alyssa Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code. By the end of this tutorial, you’ll be able to: Write Python code that conforms to PEP 8 Understand the reasoning behind the guidelines laid out in PEP […]

Read more

Python Basics Exercises: Lists and Tuples

In Python Basics: Lists and Tuples, you learned that Python lists resemble real-life lists in many ways. They serve as containers for organizing and storing collections of objects, allowing for the inclusion of different data types. You also learned about tuples, which are also collections of objects. However, while lists are mutable, tuples are immutable. In this Python Basics Exercises course, you’ll test and reinforce your knowledge of Python lists and tuples. Along the way, you’ll also get experience with […]

Read more

Building Enumerations With Python’s enum

Some programming languages, such as Java and C++, have built-in support for a data type called enumerations, commonly referred to as enums. Enums enable you to create sets of logically related constants that you can access through the enumeration itself. Unlike these languages, Python doesn’t have a dedicated syntax for enums. However, the Python standard library provides an enum module that offers support for enumerations through the Enum class. If you’re familiar with enums from other languages and wish to […]

Read more

Python News: What’s New From January 2024

In January 2024, Python 3.13.0a3 was released! With several exciting features, improvements, and optimizations, this release is the third of six planned alpha releases. During the alpha phase, features may be added up until the start of the beta phase on May 7. This is a pre-release, and you shouldn’t use it for production environments. However, it’s a great way to try out some new and exciting language features. The steering council had its elections last December, and the Python […]

Read more

Python’s Format Mini-Language for Tidy Strings

When you’re doing string interpolation in your Python code, you often need to format the interpolated values to meet some formatting requirements. To do this, Python provides what is known as the format mini-language, which defines the syntax of a format specifier. Perhaps you’re comfortable working with strings, but you want to take even more control of them. With proficiency in the format mini-language, you’ll be able to use format specifiers to do things like formatting numbers as currency values, […]

Read more

Profiling your Numba code

If you’re writing numeric Python code, Numba can be a great way to speed up your program. By compiling a subset of Python to machine code, Numba lets you write for loops and other constructs that would be too slow in normal Python. In other words, it’s similar to Cython, C, or Rust, in that it lets you write compiled extensions for Python. Numba code isn’t always as fast as it could be, however. This is where profiling is useful: […]

Read more
1 4 5 6 7 8 166