How to Get the Decimal Part of a Number in Python?

Decimal Part of a Number in Python

In this tutorial, I will explain how to get the decimal part of a number in Python. As a Python developer, I recently faced this issue while developing a financial application for a client in New York City, and I found several effective methods to handle this task. Let’s get into the details. Methods to … Read more >>

How to Convert Float to Int in Pandas

python float to int

While I was working on a data analysis project for a US retail dataset, I needed to convert price columns from float to integer format. The challenge was maintaining data accuracy while removing decimal places. In this article, I will share five practical methods to convert float values to integers in Pandas, based on my … Read more >>

How to Make a Dashed Horizontal Line in Python Matplotlib

How to Make a Dashed Horizontal Line in Python Matplotlib

When I started working with Python data visualization, I often needed to highlight specific thresholds in my plots. Sometimes, a horizontal line was the best way to do it. But instead of a solid line, I wanted a dashed horizontal line to make the chart more readable. At first, it wasn’t obvious how to do … Read more >>

How to Split a List in Python by Comma

python split string by comma

Recently, while working on a data-cleaning project, I needed to split a long list of values separated by commas into individual items. At first, I thought this would be tricky, but Python makes it surprisingly simple. With over 10 years of experience writing Python code, I’ve used this technique countless times for real-world projects. In … Read more >>

Different Ways to Create Strings in Python

creating and storing strings in python

When I first started working with Python more than ten years ago, I quickly realized how important strings were. Almost every project I worked on involved text in some way. I’ve explored many different ways to create strings in Python. Some methods are simple and quick, while others give you more flexibility. In this tutorial, … Read more >>

Get Absolute Value in Python Without Using abs() Function

python absolute value

Over my 10+ years of working with Python, I’ve often come across situations where I needed to calculate the absolute value of a number but couldn’t use the built-in abs() function. At first, this might sound unusual; after all, abs() is quick and reliable. But in real-world projects, especially coding interviews, algorithm challenges, or restricted … Read more >>

Check If a List is Empty in Python

python check if list is empty

As a developer, while working on a large data-cleaning project in Python, I had to make sure my code handled empty lists properly. The issue was simple: I needed to check whether a list was empty before performing any operations on it. If you’ve been coding in Python for a while, you know how often … Read more >>

jQuery Check if Element Has Class

jQuery Check Element Has Class

When working with dynamic web applications, you’ll often need to check whether an HTML element contains a specific CSS class. jQuery provides several powerful methods to accomplish this task efficiently. In this comprehensive guide, we’ll explore all the ways to check if an element has a class using jQuery, complete with practical examples and best … Read more >>

Booleans in Python: True, False and How to Check Them

Python booleans: the Command Prompt showing that the string False evaluates as True

A boolean in Python is a value that is either True or False, and nothing else: Both must be capitalised. Lowercase true is just an undefined name, so it raises a NameError. The trap worth knowing before anything else: bool(“False”) is True, because any non-empty string is truthy. Everything on this page was run on … Read more >>

Remove the Last Character From a String in Python

Python remove the last character from a string: the Command Prompt showing how a zero count empties the string

To remove the last character from a string in Python, slice up to -1: Two traps follow from that. Writing text[:-n] with n as a variable empties the string when n is zero, and rstrip removes more characters than you expect. Both are demonstrated below, on Python 3.12.5. Removing the last character with slicing A … Read more >>