Blog
How to Solve Python SyntaxError: unexpected character after line continuation character
In Python, we can use the backslash character \ to break a single line statement into multiple lines to make it easier to read. If we want to use this continuation character, it must be the last character of that line. The Python interpreter will raise "SyntaxError:...
How to Solve Python TypeError: ‘float’ object is not subscriptable
In Python, you cannot access values inside a float using indexing syntax. Floating-point numbers are single values, and indexing syntax is only suitable for subscriptable objects such as strings or lists. If you attempt to retrieve an individual number from a float,...
How to Solve Python TypeError: object of type ‘NoneType’ has no len()
This error occurs when you pass a None value to a len() function call. NoneType objects are returned by functions that do not return anything and do not have a length. You can solve the error by only passing iterable objects to the len() function. Also, ensure that...
How to Solve Python ValueError: too many values to unpack (expected 2)
Python raises ValueError when a function receives an argument with a correct type but an invalid value. Python valueerror: too many values to unpack (expected 2) means you are trying to access too many values from an iterator. In this tutorial, we will go through what...
How to Solve Python TypeError: ‘NoneType’ object is not callable
You will encounter the TypeError: 'NoneType' object is not callable if you try to call an object with a None value like a function. Only functions respond to function calls. In this tutorial, we will look at examples of code that raise the TypeError and how to solve...
How to Solve Python TypeError: ‘>’ not supported between instances of ‘str’ and ‘int’
In Python, we can only compare objects using mathematical operators if they are the same numerical data type. Suppose you use a comparison operator like the greater than the operator or >, between a string and an integer. In that case, you will raise the TypeError:...
How to Solve Python TypeError: ‘int’ object is not subscriptable
We raise the TypeError: 'int' object is not subscriptable when trying to treat an integer type value like an array. Subscriptable objects in Python contain or can contain other objects in order, for example, a list. Integers cannot contain other objects; they single...
How to Calculate the Hamming Distance in Python
Hamming distance is a type of string metric for finding how similar two binary data strings are. If the strings are equal in length, Hamming distance determines the number of bit positions different between them. We can also describe Hamming distance as the minimum...
Python Absolute Value
Python has several functions that are pre-defined in Python, known as built-in functions. These functions provide convenience and are very easy to use. In this tutorial, we will be looking at the abs() built-in function to calculate the absolute value of a number. As...
How to Calculate the Manhattan Distance in Python
Distances measures are essential tools for machine learning. A distance measure is a score that summarises how different two objects are in the problem domain. Usually, we calculate distance measures on rows of data, like strings representing text documents. Specific...
Suf is a senior advisor in data science with deep expertise in Natural Language Processing, Complex Networks, and Anomaly Detection. Formerly a postdoctoral research fellow, he applied advanced physics techniques to tackle real-world, data-heavy industry challenges. Before that, he was a particle physicist at the ATLAS Experiment of the Large Hadron Collider. Now, he’s focused on bringing more fun and curiosity to the world of science and research online.