Python __int__() Magic Method

Syntax object.__int__(x) The Python __int__() method implements the built-in int() function. So, when you call int(x), Python attempts to call x.__int__(). If the return value is not an integer, Python will raise a TypeError. If it’s not implemented, Python attempts to call x.__index__() instead, and only if this is not implemented either, it raises a … Read more

Python Palindromes One-Liner

This one-liner introduces another basic computer science term: palindromes. Similar to anagrams, palindromes are a popular coding interview question. First things first: What is a Palindrome? β€œA palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar or the number 10201.β€œ [source] … Read more

Finxter.com Puzzles by Topic

Arithmetic Arithmetic Operations https://app.finxter.com/learn/computer/science/314 Integer Arithmetic https://app.finxter.com/learn/computer/science/381 Python Float Arithmetic https://app.finxter.com/learn/computer/science/320 OOP Basics of OOP https://app.finxter.com/learn/computer/science/527 OOP https://app.finxter.com/learn/computer/science/606 OOP – Representation https://app.finxter.com/learn/computer/science/594 Filter Filter and Recursion https://app.finxter.com/learn/computer/science/493 Set, Lambda, and Filter https://app.finxter.com/learn/computer/science/399 The Filter Function https://app.finxter.com/learn/computer/science/375 DataFrames DataFrames and Datatypes https://app.finxter.com/learn/computer/science/614 DataFrames and Series https://app.finxter.com/learn/computer/science/612 Merging DataFrames https://app.finxter.com/learn/computer/science/621 Add Column To DataFrame https://app.finxter.com/learn/computer/science/616 DataFrame Creation … Read more

Python __float__() Magic Method

Syntax object.__float__(x) The Python __float__() method implements the built-in float() function. So, when you call float(x), Python attempts to call x.__float__(). If the return value is not a float, Python will raise a TypeError. If x.__float__() is not implemented, Python attempts to call x.__index__() first and only if this is not implemented either, it raises … Read more

Python __index__() Magic Method

Python’s __index__(self) method is called on an object to get its associated integer value. The returned integer is used in slicing or as the basis for the conversion in the built-in functions bin(), hex(), and oct(). The __index__() method is also used as a fallback for int(), float(), and complex() functions when their corresponding magic … Read more

No, Python __oct__() Doesn’t Exist Anymore. Do This Instead!

The Problem TypeError: ‘…’ object cannot be interpreted as an integer If you’re reading this article, chances are that you have been thinking something along those lines: Given a custom class My_Class. You want to override the behavior of the built-in oct(x) function in Python when calling it on a My_Class object x. You know … Read more

No, Python __hex__() Does Not Exist. Do This Instead!

The Problem TypeError: ‘…’ object cannot be interpreted as an integer If you’re reading this article, chances are that you have been thinking something along those lines: Given a custom class My_Class. You want to override the behavior of the built-in hex(x) function in Python when calling it on a My_Class object x. You know … Read more

Python Anagrams in One Line Python

Why Learning about Python Anagrams? A popular question in programming interviews is to create an anagram checker. The interviewer wants to test your knowledge about the basic terminology in computer science, and how good you are at developing your own simple algorithms to solve the problems you are facing. In this article, you’ll learn about … Read more

Python __hash__() Magic Method

Syntax object.__hash__(x) The Python __hash__() method implements the built-in hash() function. So, when you cal hash(x), Python attempts to call x.__hash__(). If the return value is not an integer or the x.__hash__() method is not defined, Python will raise a TypeError. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). … Read more

Python __complex__() Magic Method

Syntax object.__complex__(x) The Python __complex__() method implements the built-in complex() function. So, when you cal complex(x), Python attempts to call x.__complex__(). If the return value is not a complex number or the x.__complex__() method is not defined for an object on which you call complex(x), Python will raise a TypeError. We call this a “Dunder … Read more

Finxter Feedback from ~1000 Python Developers

This feedback is the collective feedback of a year’s worth of teaching hundreds of thousands of coders in our email program. Here’s the quick overview chart of all 955 responses: In case you want to join the email academy, check it out here: Let’s get started with the unfiltered list of feedback! List of 1000 … Read more

Python __bytes__() Magic Method

Syntax object.__bytes__(self) The Python __bytes__() method implements the built-in bytes() function. So, when you cal bytes(x), Python attempts to call x.__bytes__(). If the return value is not a Bytes object or the x.__bytes__() method is not defined for an object on which you call bytes(x), Python will raise a TypeError. We call this a “Dunder … Read more