Python Built-in Functions

Python reversed() — A Simple Guide with Video

Python’s built-in reversed(sequence) function returns a reverse iterator over the values of the given sequence such as a list, a tuple, or a string. Usage Learn by example! Here are some examples of how to use the reversed() built-in function. The most basic use is on a Python list: You can see that the return …

Python reversed() — A Simple Guide with Video Read More »

Python frozenset() — A Simple Guide with Video

Python’s built-in frozenset() function creates and returns a new frozenset object. A frozenset is an immutable set—so you cannot change the frozenset after creation and set methods such as add() or remove() don’t work on the frozenset. Without an argument, frozenset() returns an empty frozenset. With the optional argument, frozenset(iter) initializes the new frozenset with …

Python frozenset() — A Simple Guide with Video Read More »

Python set() Function — A Simple Guide with Video

Python’s built-in set() function creates and returns a new set object. A set is an unordered collection of unique elements. Without an argument, set() returns an empty set. With the optional argument, set(iter) initializes the new set with the elements in the iterable. Read more about sets in our full tutorial about Python Sets. Usage …

Python set() Function — A Simple Guide with Video Read More »

How Does Tuple Comparison Work In Python?

A Quick Introduction To Tuples Python consists of 4 built-in data types that are used to store collections of data. These data types are: List Set Dictionary Tuple A tuple allows you to store multiple items within a single variable. Hence, it is a collection that is ordered and unchangeable/immutable. Also, tuples are heterogeneous as …

How Does Tuple Comparison Work In Python? Read More »

Python format() Function: No-BS Guide by Example

The web is filled with shitty tutorials about Python’s formatting feature. At times, it can become really confusing—and it’s hard to see the forest for the trees. In this tutorial, I’ll try to gradually build a basic understanding of the built-in format() function, what it does, and how you can use it to become a …

Python format() Function: No-BS Guide by Example Read More »

Python float() Function

Python’s built-in float(value) function converts the argument value to a float number. For example, float(’42’) converts the string value ’42’ into the float number 42.0. Argument value A Python object to be converted into a float number. The value object must have an __float__() method that returns the associated float number—otherwise a ValueError will be …

Python float() Function Read More »

Python int() Function

Python’s built-in int(value) function converts the argument value to an integer number. For example, int(’42’) converts the string value ’42’ into the integer number 42. The int() function on a float argument rounds down to the closest integer. Argument value A Python object to be converted into an integer number. The value object must have …

Python int() Function Read More »

How to Fix “TypeError: len() of unsized object”

Problem Formulation: How to fix the TypeError: len() of unsized object? TypeError: len() of unsized object There are many possible ways why this array may occur. One common pitfall is to use the len() function on a NumPy array with only one value. Example: Let’s consider the minimal example that creates this error message! Reason …

How to Fix “TypeError: len() of unsized object” Read More »