by Suf | Apr 24, 2022 | Programming, Python, Tips
If you try to reference a local variable before assigning a value to it within the body of a function, you will encounter the UnboundLocalError: local variable referenced before assignment. The preferable way to solve this error is to pass parameters to your function,...
by Suf | Apr 24, 2022 | Programming, Python, Tips
If you try to parse invalid JSON or decode an empty string as JSON, you will encounter the JSONDecodeError: Expecting value: line 1 column 1 (char 0). This error can occur if you read an empty file using json.load, read an empty JSON or receive an empty response from...
by Suf | Apr 23, 2022 | Programming, Python, Tips
The min() function is built into Python and returns the item with the smallest value in an iterable or the item with the smallest value from two or more objects of the same type. When you pass an iterable to the min() function, such as a list, it must have at least...
by Suf | Apr 22, 2022 | Programming, Python, Tips
In Python, bool is the type for the Boolean object, which is an object that represents one of two values: True or False. You cannot retrieve items from a Boolean value using the subscript operator [] like you can with a list or a tuple. If you try to use the subscript...
by Suf | Apr 20, 2022 | Programming, Python, Tips
In Python, NoneType is the type for the None object, which is an object that indicates no value. Functions that do not return anything return None, for example, append() and sort(). You cannot retrieve items from a None value using the subscript operator [] like you...
by Suf | Apr 19, 2022 | Programming, Python, Tips
If you try to perform a mathematical operation that calls the universal function ufunc.reduce on NumPy arrays containing numerical strings, you will raise the TypeError: cannot perform reduce with flexible type. To solve this error, you can cast the values in the...