Python: 3 ways to remove empty lines from a string
Updated: May 20, 2023
A multiple-line string might contain one or many empty lines. Empty lines refer to lines in a text or string that contain no visible content or characters. They are lines that appear blank or have only whitespace characters, such as......
Python: How to unescape HTML entities in a string
Updated: May 20, 2023
Overview HTML entities are special characters that are used to represent characters that have special meaning in HTML or that are not part of the character set. They start with an ampersand (&) and end with a semicolon (;). Some......
Python: 5 ways to remove HTML tags from a string
Updated: May 20, 2023
This concise, example-based article will walk you through some different approaches to stripping HTML tags from a given string in Python (to get plain text). The raw HTML string we will use in the examples to come is shown......
Python: 2 Ways to Extract Plain Text from a Webpage
Updated: May 19, 2023
The raw HTML data of a webpage includes many things, from HTML tags, images, JavaScript codes, etc. Sometimes, you just need plain text for data analytics, machine learning, or something else. This article will show you 2 ways to get what......
Python: Checking System RAM/CPU/Disk Usage
Updated: May 19, 2023
This succinct, practical article shows you how to programmatically check RAM (memory), CPU, and disk usage in Python. You can get the job done painlessly by using a package called psutil. Install it by performing the following......
Python Generic Types: Tutorial & Examples
Updated: Mar 04, 2023
This concise article is about generic types in Python. Overview Generic types allow us to define classes, functions, or methods that can work with different data types without specifying the exact data type beforehand. This is......
Python: Defining Functions with Type Hints
Updated: Mar 04, 2023
This concise, example-based article shows you how to define functions with type hints in Python. Overview Python 3.5 introduced Type Hints which allows you to specify the data type of a function’s parameters and return value.......
Python Data Types Cheat Sheet
Updated: Mar 04, 2023
A succinct, comprehensive cheat sheet for Python data types. You can use it for quick lookup during your work. TypeDescriptionExampleintinteger values123, -120, 0floatfloating-point values1.21, 3.141, -9.8boolBoolean valuesTrue,......
Python: How to Use Class Decorators with Dataclass
Updated: Mar 01, 2023
This concise, straight-to-the-point article shows you how to use class decorators with dataclass in Python. We’ll take a look at the fundamentals and then walk through a couple of practical examples. The......
Python: How to Set Default Values in Dataclass
Updated: Mar 01, 2023
This succinct, straightforward article shows you how to set default values in a dataclass in Python. Setting Default Values in Dataclass To set default values in a dataclass, we can use simple syntax like a variable declaration or......
Python: How to Validate Data in Dataclass
Updated: Mar 01, 2023
This concise example-based article shows you how to validate data with Python dataclasses. Basic Example Data validation is an essential part of any data processing system. It ensures that the data received by the system is correct......
How to Use Inheritance with Dataclass in Python
Updated: Mar 01, 2023
The dataclasses module brings to the table a great way to create simple and lightweight data structures in Python. However, sometimes you need more complex data structures that require inheritance. Inheritance is a powerful feature in......