How to find if a string contains the substring in Python ?

A substring is a small portion of the string. When working with strings, a common use case is to check if a given substring is present in a string or not. Python supports various built-in functions which can be used to find if a string contains the given substring or not. In today’s short tutorial let’s learn different ways of checking if a string contains the substring in Python. Note: In certain cases, the kind of strings you get to work on is not in your control. You might get None object or an empty string. Not all the methods … Read more

How to fix TypeError: list indices must be integers or slices not str

The TypeError: list indices must be integers or slices, not str is seen when you’re accessing the list with a string object instead of an integer object. This is a very simple error. The error statement clearly signifies the error. It says that we are indexing the list using a string object instead of an integer or slices Also check, How to fix the TypeError: list indices must be integers or slices, not a tuple. What causes the TypeError: list indices must be integers or slices, not str? In Python, lists can be indexed only with integer objects or slices. … Read more

How to solve TypeError: Object of type int32 is not JSON serializable in Python

The TypeError: Object of type int32 is not JSON serializableĀ is seen when the type of the object we pass cannot be turned into a JSON object. JSON accepts int, float type of objects. However, when you pass the int32 or int64 type of objects (data types supported by numpy) you see an error as these data types are not supported in JSON. To get rid of this error, convert the object to the int object type. In this article, let us see what causes this error and also look at ways of fixing this error. Also check, How to Fix … Read more