Python tutorials

Matplotlib Stack Plot – Tutorial and Examples

Introduction There are many data visualization libraries in Python, yet Matplotlib is the most popular library out of all of them. Matplotlib’s popularity is due to its reliability and utility – it’s able to create both simple and complex plots with little code. You can also customize the plots in a variety of ways. In this tutorial, we’ll cover how to plot Stack Plots in Matplotlib. Stack Plots are used to plot linear data, in a vertical order, stacking each […]

Read more

Understanding Python List Comprehensions

One of Python’s most distinctive features is the list comprehension, which you can use to create powerful functionality within a single line of code. However, many developers struggle to fully leverage the more advanced features, or use them too much, which can lead to code that’s less efficient and harder to read. By the end of this course, you’ll understand the full power of Python list comprehensions and how to use their features comfortably. You’ll also gain an understanding of […]

Read more

OrderedDict vs dict in Python: The Right Tool for the Job

Sometimes you need a Python dictionary that remembers the order of its items. In the past, you had only one tool for solving this specific problem: Python’s OrderedDict. It’s a dictionary subclass specially designed to remember the order of items, which is defined by the insertion order of keys. This changed in Python 3.6. The built-in dict class now keeps its items ordered as well. Because of that, many in the Python community now wonder if OrderedDict is still useful. […]

Read more

How to Print Colored Text in Python

Introduction It’s typical for CLI apps to return text in the same color of the terminal. There are always cases when we want to highlight output to the user, for example, a warning or error message. In those cases, a dash of color could make a difference. This article shows you how to print colored output in the terminal in Python with and without libraries. ANSI Escape Sequences Your Teletypewriter (TTY), or rather your terminal, is not only capable of […]

Read more

Parse Datetime Strings with parsedatetime in Python

Introduction In this tutorial, we’ll take a look at how to parse Datetime with parsedatetime in Python. To use the parsedatetime package we first need to install it using pip: $ pip install parsedatetime Should pip install parsedatetime fail, the package is also opensource available on Github. Convert String to Python’s Datetime Object with parsedatetime The first, and most common way to use parsedatetime is to parse a string into a datetime object. First, you’ll want to import the parsedatetime […]

Read more

Python Community Interview With Dane Hillard

Today I’m joined by Dane Hillard, lead web application developer at ITHAKA and author of Practices of the Python Pro. Dane is also a Real Python tutorial author. In this interview, we discuss a variety of topics, including code complexity, Python package maintenance, and popcorn. So without further ado, let’s welcome Dane. Ricky: Thanks for joining me for this interview, Dane. I’d like to start in the same manner we do with all our guests: how did you get into programming, […]

Read more

Records and Sets: Selecting the Ideal Data Structure

There are a variety of ways for storing and managing data in your program and the choice of the right data structure has an effect on the readability of your code, ease of writing, and performance. Python has a wide selection of built-in mechanisms that meet most of your data structure needs. This course introduces you to two types of data structures: data records and sets. There are multiple types and classes for both of these data structures and this […]

Read more

Build an Asteroids Game With Python and Pygame

Do you want to create your own computer games but like Python too much to abandon it for a career as a game developer? There’s a solution for that! With the Pygame module, you can use your amazing Python skills to create games, from the basic to the very complex. Below, you’ll learn how to use Pygame by making a clone of the Asteroids game! In this tutorial, you’ll learn how to build a complete game, including: Loading images and […]

Read more

Matplotlib: Draw Vertical Lines on Plot

Introduction Matplotlib is one of the most widely used data visualization libraries in Python. Much of Matplotlib’s popularity comes from its customization options – you can tweak just about any element from its hierarchy of objects. In this tutorial, we’ll take a look at how to draw a vertical line on a Matplotlib plot, that allows us to mark and highlight certain regions of the plot, without zooming or changing the axis range. Creating a Plot Let’s first create a […]

Read more

Validating and Formatting Phone Numbers in Python with phonenumbers

Introduction Validating phone numbers can be a very challenging task. The format of a phone number can vary from one country to another. Heck, it can also vary within the same country! Some countries share the same country code, while some other countries use more than one country code. According to an example from the Google’s libphonenumber GitHub repository, USA, Canada, and Caribbean islands, all share the same country code (+1). On the other hand, it is possible to call […]

Read more
1 127 128 129 130 131 184