Python tutorials

Python any(): Powered Up Boolean Function

As a Python programmer, you’ll frequently deal with Booleans and conditional statements—sometimes very complex ones. In those situations, you may need to rely on tools that can simplify logic and consolidate information. Fortunately, any() in Python is such a tool. It looks through the elements in an iterable and returns a single value indicating whether any element is true in a Boolean context, or truthy. In this course, you’ll learn how to: Use any() and not any() Elimate long or […]

Read more

Python’s zipfile: Manipulate Your ZIP Files Efficiently

Python’s zipfile is a standard library module intended to manipulate ZIP files. This file format is a widely adopted industry standard when it comes to archiving and compressing digital data. You can use it to package together several related files. It also allows you to reduce the size of your files and save disk space. Most importantly, it facilitates data exchange over computer networks. Knowing how to create, read, write, populate, extract, and list ZIP files using the zipfile module […]

Read more

Faster Python calculations with Numba: 2 lines of code, 13× speed-up

Python is a slow language, so computation is best delegated to code written in something faster. You can do this with existing libraries like NumPy and SciPy, but what happens when you need to implement a new algorithm, and you don’t want to write code in a lower-level language? For certain types of computation, in particular array-focused code, the Numba library can significantly speed up your code. Sometimes you’ll need to tweak it a bit, sometimes it’ll just work with […]

Read more

Python’s all(): Check Your Iterables for Truthiness

When programming, you’ll often need to check if all the items in an iterable are truthy. Coding this functionality repeatedly can be annoying and inefficient. Luckily, Python provides the built-in all() function to solve this problem. This function takes an iterable and checks all its items for truth value, which is handy for finding out if those items have a given property or meet a particular condition. Python’s all() is a powerful tool that can help you write clean, readable, […]

Read more

Defining Python Functions With Optional Arguments

Defining your own functions is an essential skill for writing clean and effective code. In this tutorial, you’ll explore the techniques you have available for defining Python functions that take optional arguments. When you master Python optional arguments, you’ll be able to define functions that are more powerful and more flexible. In this course, you’ll learn how to: Distinguish between parameters and arguments Define functions with optional arguments and default parameter values Define functions using args and kwargs Deal with […]

Read more

Python News: What’s New From January 2022?

In January 2022, the code formatter Black saw its first non-beta release and published a new stability policy. IPython, the powerful interactive Python shell, marked the release of version 8.0, its first major version release in three years. Additionally, PEP 665, aimed at making reproducible installs easier by specifying a format for lock files, was rejected. Last but not least, a fifteen-year-old memory leak bug in Python was fixed. Let’s dive into the biggest Python news stories from the past […]

Read more

Finding leaked secrets in your Docker image with a scanner

If you’re not careful, you can end up with a private SSH key, AWS access token, or password embedded in your Docker image. That means anyone who access the image will be able to get that secret, and potentially use it to gain further access to additional systems. While you can and should take steps to prevent leaking secrets in the first place, it’s still useful to catch leaks if they do happen. If you can catch the leak before […]

Read more

Using Python’s pip to Manage Your Projects’ Dependencies

Watch Now This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding: A Beginner’s Guide to Pip The standard package manager for Python is pip. It allows you to install and manage packages that aren’t part of the Python standard library. If you’re looking for an introduction to pip, then you’ve come to the right place! In this tutorial, you’ll learn how to: Set up pip […]

Read more

Python’s len() Function

In many situations, you’ll need to find the number of items stored in a data structure. Python’s built-in function len() is the tool that will help you with this task. There are some cases in which the use of len() is straightforward. However, there are other times when you’ll need to understand how this function works in more detail and how to apply it to different data types. In this course, you’ll learn how to: Find the length of built-in […]

Read more
1 96 97 98 99 100 181