Python tutorials

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

Draw the Mandelbrot Set in Python

This tutorial will guide you through a fun project involving complex numbers in Python. You’re going to learn about fractals and create some truly stunning art by drawing the Mandelbrot set using Python’s Matplotlib and Pillow libraries. Along the way, you’ll learn how this famous fractal was discovered, what it represents, and how it relates to other fractals. Knowing about object-oriented programming principles and recursion will enable you to take full advantage of Python’s expressive syntax to write clean code […]

Read more

Raining Outside? Build a Weather CLI App With Python

You’re stuck inside because of torrential rains—again! You wonder what the weather’s like in that faraway city where your friends from the Real Python community live. You’d rather stick around in your command-line interface (CLI) than look it up in your browser. If that sounds like a task you’d want to tackle by building a command-line weather app using only the Python standard library, then this tutorial is for you. In this tutorial, you’ll learn how to: Build a functional […]

Read more

The fastest way to read a CSV in Pandas

You have a large CSV, you’re going to be reading it in to Pandas—but every time you load it, you have to wait for the CSV to load. And that slows down your development feedback loop, and might meaningfully slows down your production processing. But it’s faster to read the data in faster. Let’s see how. In this article we’ll cover: Pandas’ default CSV reading. The faster, more parallel CSV reader introduced in v1.4. A different approach that can make […]

Read more

Looping With Python enumerate()

In Python, a for loop is usually written as a loop over an iterable object. This means that you don’t need a counting variable to access items in the iterable. Sometimes, though, you do want to have a variable that changes on each loop iteration. Rather than creating and incrementing a variable yourself, you can use Python’s enumerate() to get a counter and the value from the iterable at the same time! In this course, you’ll see how to: Use […]

Read more
1 100 101 102 103 104 185