Python tutorials

Duck Typing in Python: Writing Flexible and Decoupled Code

Python makes extensive use of a type system known as duck typing. The system is based on objects’ behaviors and interfaces. Many built-in classes and tools support this type system, which makes them pretty flexible and decoupled. Duck typing is a core concept in Python. Learning about the topic will help you understand how the language works and, more importantly, how to use this approach in your own code. In this tutorial, you’ll learn: What duck typing is and what […]

Read more

What can you do about climate change?

Climate change is impacting the whole planet, and getting worse every year. So you want to do something—but you’re not sure what. If you do some research you might encounter an essay by Bret Victor—What can a technologist do about climate change? There’s a whole pile of good ideas in there, and it’s worth reading, but the short version is that you can use technology to “create options for policy-makers.” And working on clean energy or efficiency is definitely a […]

Read more

How to Read User Input From the Keyboard in Python

You may often want to make your Python programs more interactive by responding dynamically to input from the user. Learning how to read user input from the keyboard unlocks exciting possibilities and can make your code far more useful. The ability to gather input from the keyboard with Python allows you to build programs that can respond uniquely based on the preferences, decisions, or data provided by different users. By fetching input and assigning it to variables, your code can […]

Read more

Unleashing the Power of the Console With Rich

Python’s Rich package is a versatile tool kit that enables you to generate beautifully formatted and highlighted text in the console. It extends beyond this to help you build captivating text-based user interfaces (TUIs). But why opt for a TUI instead of a graphical user interface (GUI)? There are instances where a text interface feels more fitting. Why employ a complex GUI for a simple application when an elegant text interface suffices? Working with plain text can be refreshing. It […]

Read more

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
1 28 29 30 31 32 191