Python Slicing Bootscamp

Slicing is one of the most popular Python features. Thus, understanding slicing is key to understand existing code bases. In this tutorial, I’m going to train your slicing skills. Ready? So, let’s go! ? Watch the Video Python Slicing Read About Slicing Slicing is a Python-specific concept for accessing a range of values in sequence … Read more

Python sorted() Function

If you work in a data driven career, odds are you will at some point have to perform sorting on your data. Rather than writing your own sorting algorithm (which will most likely be far less efficient), Python provides a built-in function called sorted(). This function allows you to do basic sorting, such as arranging … Read more

Python callable() Function

Python’s built-in callable(object) returns True if you could call the object argument like a function with the trailing parentheses in object(). You can make any object callable by implementing the instance’s __call__() method. For example, callable(callable) returns True because callable is a function object. But callable(3) returns False because an integer is not a function … Read more

Python bytes() Function

Python’s built-in bytes(source) function creates an immutable bytes object initialized as defined in the function argument source. A bytes object is like a string but it uses only byte characters consisting of a sequence of 8-bit integers in the range 0<=x<256. The returned byte object is immutable—you cannot change it after creation. If you plan … Read more

Scipy Interpolate 1D, 2D, and 3D

In this article we will explore how to perform interpolations in Python, using the Scipy library. Scipy provides a lot of useful functions which allows for mathematical processing and optimization of the data analysis. More specifically, speaking about interpolating data, it provides some useful functions for obtaining a rapid and accurate interpolation, starting from a … Read more

Python bin() Function

Python’s built-in bin(integer) function takes one integer argument and returns a binary string with prefix “0b”. If you call bin(x) on a non-integer x, it must define the __index__() method that returns an integer associated to x. Otherwise, it’ll throw a TypeError: object cannot be interpreted as an integer. Argument integer An integer value or … Read more

Python ascii() Function

Python’s built-in ascii(object) function takes one object argument and returns the string representation of that object. The function calls the repr() built-in function and replaces non-ASCII characters with the character code \x. For example, calling ascii(‘MΓΌnchen’) results in the ascii string ‘M\xfcnchen’ by replacing character ΓΌ with character code \xfc. Argument object Iterable such as … Read more

Premature Optimization is the Root of All Evil

This chapter draft is part of my upcoming book “The Art of Clean Code” (NoStarch 2022). You’ll learn about the concept of premature optimization and why it hurts your programming productivity. Premature optimization is one of the main problems of poorly written code. But what is it anyway? Definition Premature Optimization Definition: Premature optimization is … Read more

Python any() Function

Python’s built-in any(x) function takes one iterable as an argument x such as a list, tuple, or dictionary. It returns True if at least one of the elements in the iterable evaluates to True using implicit Boolean conversion, otherwise it returns False. If the iterable is empty, e.g., any([]), it returns False because the condition … Read more