Every Built-In Python Function

January 5, 2024

In this 4th post in the "Every _____" series, we will be looking at every built-in function in the Python programming language. Python, one of the most popular programming languages, is well known for it's readability and simple syntax. Like previous posts, I will be rating each function from S to F tier based on how I perceive it's functionality, usefulness, and importance.

  1. abs(): The Absolute Value Function

    Starting off our list we have a useful math function. abs() will return the absolute value of any number passed to it.

    abs(x)
    

    Interestingly, since Python has built-in support for complex numbers, abs() can be used to find the absolute value of a complex number. This has tons of different uses, especially in terms of calculating distances between points.

    Rating: B

  2. aiter(): The Asynchronous Iterator Function

    This function is interesting in terms of being relatively new to Python, only being included since version 3.10. It returns an asynchronous iterator for an asynchronous iterable.

    aiter(async_iterable)
    

    Now, I haven't used asynchronous iterators in Python before, but I suspect they are fairly useful. When I use JavaScript, especially for this site, many of the functions I use are asynchronous. If you're not sure what that means, asynchronous essentially means we can run something while something else is also going on. For example, if we want to fetch a large amount of info from a database, it could take some time to do so, and if this is on a website, we do not want to halt the loading of a website in order to fetch the data. So instead, we fetch the data asynchronously, meaning we begin fetching data and load the website while the data is being fetched.

    For an iterator, being asynchronous could be useful for iterating in the background while a process is already occuring. However, since this is fairly limited in terms of scope of usability, the rating will be somewhat limited.

    Rating: C

  3. all(): The All Function

    Unlike the last function, this one is pretty straight forward. all() returns True if an all the elements in a passed iterable are True (or if the iterable is empty).

    all(iterable)
    

    This could have a wide range of uses. One example I can think of is having an array where the index is True or False depending on if you pick up a coin in a video game. We could easily use all() to check if all coins were collected.

    Rating: A

  4. anext(): The Asynchronous Next Function

    Also new to Python 3.10, this function, when awaited, returns the next item from a given asynchronous iterator.

    anext(async_iterator)
    anext(async_iterator, default)
    

    We can also provide a second parameter to return a default value after the iterator is exhausted. This is just like how iteration is done with a regular iterator, but now it works asynchronously.

    Rating: C

  5. any(): The Any Function

    The companion to all(), we have any(), which returns true if any element in the passed iterable is True (it also returns False if empty).

    any(iterable)
    

    I think the reason I like any and all so much is because they are so versatile. They could be used for countless purposes, which results in a higher rating. I also like them since they are easy to understand, which is the goal of Python.

    Rating: A

  6. ascii() The ASCII Function

    This function returns a string representation of an object using ASCII characters.

    ascii(object)
    

    For the most part, this just returns a regular string representation of the object, and is only important when working with non-ASCII characters. Therefore, this function isn't all too useful.

    Rating: D

Back to Blog