Python tutorials

Python’s “in” and “not in” Operators: Check for Membership

Python’s in and not in operators allow you to quickly determine if a given value is or isn’t part of a collection of values. This type of check is common in programming, and it’s generally known as a membership test in Python. Therefore, these operators are known as membership operators. In this tutorial, you’ll learn how to: Perform membership tests using the in and not in operators Use in and not in with different data types Work with operator.contains(), the […]

Read more

How to Get and Use the Current Time in Python

Getting the current time in Python is a nice starting point for many time-related operations. One very important use case is creating timestamps. In this tutorial, you’ll learn how to get, display, and format the current time with the datetime module. To effectively use the current time in your Python applications, you’ll add a few tools to your belt. For instance, you’ll learn how to read attributes of the current time, like the year, minutes, or seconds. To make the […]

Read more

It’s time to stop using Python 3.7

Upgrading to new software versions is work, and work that doesn’t benefit your software’s users. Users care about features and bug fixes, not how up-to-date you are. So it’s perhaps not surprising how many people still use Python 3.7. As of December 2022, almost 30% of packages downloaded from PyPI were for Python 3.7. This includes automated downloads as part of CI runs, so it doesn’t mean 3.7 is used in 30% of applications, but that’s still a lot of […]

Read more

Build Command-Line Interfaces With Python’s argparse

Command-line apps may not be common in the general user’s space, but they’re present in development, data science, systems administration, and many other operations. Every command-line app needs a user-friendly command-line interface (CLI) so that you can interact with the app itself. In Python, you can create full-featured CLIs with the argparse module from the standard library. In this article, you’ll learn how to: Get started with command-line interfaces Organize and lay out a command-line app project in Python Create […]

Read more

Python Basics: Dictionaries

In plain English, a dictionary is a book containing the definitions of words. Each entry in a dictionary has two parts: the word being defined, and its definition. Python dictionaries, like lists and tuples, store a collection of objects. However, instead of storing objects in a sequence, dictionaries hold information in pairs of data called key-value pairs. That is, each object in a dictionary has two parts: a key and a value. Each key is assigned a single value, which […]

Read more

My Favorite Way to Smooth Noisy Data With Python

Nearly all real-world data is noisy. What do I mean by noisy? Consider the following simple example: I’ve got a mass attached to a spring — I pull on the mass (stretching the spring) and then let go. From intuition, we know that the mass will oscillate up and down until it eventually comes to rest because of friction/damping in the system. If I were to plot the height of the mass over time I would get a plot like […]

Read more
1 46 47 48 49 50 181