Browse by Topic

Popular

Latest

Latest Python Posts

Diagram showing Python's operator dispatch from left operand to reflected operator on the right operand
Python

Python Reflected Operators: __radd__ and __rsub__

Python reflected operators are called when the left operand can’t handle a binary operation. See how __radd__ and __rsub__ work, when to implement them, and how to avoid common mistakes.

pythonoperator overloadingdunder methodsreflected operators
Illustration of two Python objects being compared with operator symbols, representing comparison operator overloading in a class.
Python

Python Comparison Operator Overloading

Overload Python comparison operators in custom classes with dunder methods, handle type mismatches with NotImplemented, and keep hashing consistent.

operator overloadingdunder methodspython classestotal_ordering
Illustration of Python __eq__ method overloading for custom equality comparison.
Python

Python __eq__ Operator Overloading

Learn how to override __eq__ in Python to implement value-based equality, use NotImplemented for unsupported types, and keep immutable objects hashable.

PythonOperator OverloadingDunder MethodsEquality
A Python code editor showing POS tagging output with words labeled as nouns, verbs, and adjectives.
Python

Python POS Tagging: NLTK vs spaCy vs TextBlob

Learn how to perform part-of-speech tagging in Python using NLTK, spaCy, and TextBlob, with code examples and practical tradeoffs.

POS taggingNLTKspaCyTextBlob
A Python class diagram with a unary minus operator transforming an object into a negated version
Python

Python __neg__: Implementing Unary Negation

Learn how to implement Python's __neg__ dunder method to support unary negation in custom classes, with practical examples and common pitfalls.

Pythondunder methodsoperator overloadingunary operators
Diagram showing the pow() function and ** operator for exponentiation in Python.
Python

Python pow() Function and the ** Operator

How Python's pow() function and the ** operator handle exponentiation, including the three-argument modular form, return types, and when to use each.

powexponentiationmodular arithmeticPython built-in
Number line diagram showing floor division rounding down to negative infinity for positive and negative dividends.
Python

Python Floor Division: How the // Operator Works

Learn how Python's floor division operator // works with integers and floats, including negative numbers, the modulo relationship, and common pitfalls.

pythonfloor-divisioninteger-arithmeticoperators
A stylized Python code block with a division operator and a custom class definition, illustrating the __truediv__ method.
Python

Python __truediv__: Implementing True Division

Learn how to implement Python's __truediv__ method to control true division behavior in custom classes, handle edge cases, and integrate with operator overloading.

pythonoperator overloadingdunder methodsdivision
A Python code editor showing a custom class with a __mul__ method that overloads the multiplication operator.
Python

Implementing Python's __mul__ for Custom Classes

Learn how to implement Python's __mul__ method to overload the multiplication operator, handle reflected operands with __rmul__, and avoid common pitfalls.

operator overloadingdunder methodscustom classespython oop
A diagram showing text flowing through a regular expression substitution step, with matched segments replaced by new values.
Python

Python re.sub: Replace Text with Regular Expressions

Learn how to use Python's `re.sub()` for regex-based text replacement, including replacement functions, backreferences, count, flags, and escaping pitfalls.

re.subregular expressionsstring manipulationtext processing