Pages

Topics

Tools

↑↓navigate↵openescclose

Python guides

Every published Python guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Python guides

Illustration of NaN comparison showing NaN not equal to NaN in Python
Python

Python NaN Comparison: Why NaN != NaN and How to Check It

python nan comparison: Learn why NaN never equals itself in Python and how to correctly check for NaN using math.isnan, numpy.isnan, and pandas.isna.

NaNPythonfloatnumpy
A visual representation of a floating-point number with a missing piece, symbolizing NaN in Python.
Python

Python Float NaN: Detection and Handling

How Python float NaN behaves, why it never equals itself, and how to detect and handle NaN in data processing, serialization, and numerical computations.

NaNfloating-pointmath.isnandata cleaning
Illustration of Python float infinity concept showing a number line extending beyond finite range.
Python

Python Float Infinity: Creation, Checks, and Pitfalls

Learn how to create and test positive and negative infinity as Python floats, understand arithmetic and comparison behavior, and avoid serialization and conversion pitfalls.

pythonfloating-pointinfinitymath
A visual metaphor of a Python string being converted to a floating-point number with error handling.
Python

Python String to Float: Conversion and Error Handling

python string to float: Learn how to convert Python strings to float using the float() function, handle ValueError, and manage edge cases like locale and precision.

string-to-floatfloat-parsingerror-handlingtype-conversion
Illustration of Python int to float conversion showing an integer value transforming into a floating-point number.
Python

Python int to float: Conversion and Precision

python int to float: Learn how to convert integers to floats in Python, including explicit and implicit conversion, precision behavior, and practical use cases.

PythonType ConversionFloating PointNumeric Operations
Illustration of Python's round() function showing a floating-point number being rounded to the nearest integer on a number line.
Python

Python round() Function: Syntax, Precision, and Pitfalls

Learn how Python's round() function handles syntax, banker's rounding, floating-point precision limits, and when to use Decimal for exact decimal arithmetic.

pythonroundingfloating-pointdecimal
A stylized illustration of a Python float being rounded with a magnifying glass revealing binary digits and a decimal point.
Python

Python Float Rounding: How to Round Correctly

Understand how Python rounds floats, why round() can behave unexpectedly, and when to use Decimal or formatting for precise control.

Pythonfloating-pointroundingDecimal
Illustration of two floating-point numbers being compared with a tolerance threshold, showing a close-up of a scale and a checkmark.
Python

Python Float Comparison: How to Compare Floats Correctly

python float comparison: Learn why direct float equality fails and how to compare floats reliably using tolerance, math.isclose, and practical testing strategies.

floating pointmath.isclosetoleranceunit testing
Illustration of a Python float being approximated by a binary fraction, showing the gap between decimal and binary representation.
Python

Python Float Precision: Handling Rounding Errors

Python floats are binary approximations. Understand why operations like `0.1 + 0.2` can be inexact, how to inspect the stored value, and when to use Decimal.

float precisionIEEE 754Decimal modulerounding errors
Editorial thumbnail showing a number line where 0.1 plus 0.2 lands slightly past 0.3, illustrating floating point precision error.
Python

Python Floating Point: Precision, Errors, and Fixes

Learn why 0.1 + 0.2 is not 0.3 in Python, how binary floating point works, and how to compare, round, and choose the right numeric type.

floating-pointnumeric-precisiondecimal-moduleieee-754