How To Apply A Function To Each Element Of A Tuple?

This article shows you how to apply a given function to each element of a tuple. The best way to apply a function to each element of a tuple is the Python built-in map(function, iterable) function that takes a function and an iterable as arguments and applies the function to each iterable element. An alternate … Read more

Python Named Tuple Methods

Background Python’s namedtuple() is an integral part of the Collections library and an immutable container type. Values, once set, can not be modified. You can access values by referencing them via the index or name attribute. The namedtuple() work similar to tuples. However, namedtuple() has additional functionality. This article touches on a few of these … Read more

Python Return Tuple From Function

Do you need to create a function that returns a tuple but you don’t know how? No worries, in sixty seconds, you’ll know! Go! ? A Python function can return any object such as a tuple. To return a tuple, first create the tuple object within the function body, assign it to a variable your_tuple, … 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 … Read more

Python len()

Python’s built-in function len() returns the length of the given string, array, list, tuple, dictionary, or any other iterable. The type of the return value is an integer that represents the number of elements in this iterable. Usage Learn by example! Here are some examples on how to use the len() built-in function. The examples … Read more

Python tuple() — A Simple Guide with Video

Python’s built-in tuple() function creates and returns a new tuple object. When used without an argument, it returns an empty tuple. When used with the optional iterable argument, it initializes the new tuple with the elements in the iterable. Read more about tuples in our full tutorial about Python Tuples. Usage Learn by example! Here … Read more

Arbitrary Argument Lists in Python

An arbitrary argument list is a Python feature to call a function with an arbitrary number of arguments. It’s based on the asterisk “unpacking” operator *. To catch an arbitrary number of function arguments in a tuple args, use the asterisk syntax *args within your function definition. For example, the function def f(*args): … allows … Read more