Python’s && Equivalent: Logical And

In Python, the equivalent of && (logical-and) in programming languages such as C++ or Java in an if-statement is and. Using && will raise a SyntaxError, so use and instead! Overview Problem: What is the equivalent of &&(logical-and) in Python? Example: Let’s have a look at the following example: Output: You will get the following … Read more

Read from Stdin in Python

[toc] Problem Statement: Reading from stdin in Python. Reading inputs from the user is one of the fundamental building blocks that we learn while learning any programming language. The output of most codes depends on the user’s inputs. Hence, in this article, we are going to learn how to read from stdin in Python. There … Read more

[ERROR FIXED] “Attempted relative import in non-package” even with __init__.py

[toc] Understanding the Error Problem Formulation: How to fix or deal with the following error – ” Attempted relative import in non-package”? Let’s say you have been working on your new project, and now you have decided to organize your project files properly. Hence, you move certain functions to another file to make your code … Read more

[FIXED] fatal error: Python.h: No such file or directory

[toc] Problem Statement: How to fix “fatal error: Python.h: No such file or directory“? What is a “fatal” error? A fatal error causes a program to end with practically no warning without even saving its state. It usually occurs when an application attempts to access a piece of invalid information or data. The program closes … Read more

[FIXED] UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte

Introduction Problem Statement: How to fix “UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte” in Python? Using a specific standard to convert letters, symbols and numbers from one form to another is termed as Encoding. A Unicode character can be encoded using a variety of encoding schemes. The most common … Read more

Convert Bytes to String [Python]

[toc] Overview Problem Statement: How to convert bytes data to string data in Python? Example: The following example illustrates how the decode() method converts a byte string to string. (We will dive into the details of this solution soon!) Output: Note: Difference between Byte and String Objects in Python Strings are normal sequences of characters, … Read more

How to Change The Size of Figures Drawn with Matplotlib?

[toc] If you want to dive deep into this mind-blowing library, please feel free to have a look at this tutorial – Matplotlib β€” A Simple Guide with Videos. However, in this tutorial, we will focus upon our mission-critical question, i.e., How do you change the size of figures drawn with matplotlib? Note: Before diving … Read more