Python Built-in Functions

How to Print a Float Without Scientific Notation in Python?

Problem Formulation If you print a float value in Python that is smaller than 0.0001, Python will use the scientific notation for small numbers such as 1e-05 that is short for 1*1/10**-5. Here’s an example output when printing smaller and smaller floats to the shell. If there are more than three zeros after the decimal …

How to Print a Float Without Scientific Notation in Python? Read More »

Python Print Without Space

Problem Formulation Python’s print() function allows an arbitrary number of comma-separated values and prints them to the shell, separated by a single empty space character ‘ ‘. The following example shows how you pass four string values as arguments into the print() function: The resulting shell output has an added empty space character ‘ ‘ …

Python Print Without Space Read More »

Understanding Generators In Python

If there is one subject in Python that creates confusion, it is that of generators. Generators are functions, but they have several differences from the ordinary functions you and I use daily. Today, we’ll be taking a gentle immersion into the world of generators to understand what they are, how they differ from ordinary functions, …

Understanding Generators In Python Read More »

How to Convert a String to a Double in Python?

Problem Formulation Given a string containing digits such as ‘123.456’. How to convert it to a double in Python such as 123.456? Solution Python doesn’t provide an explicit “double” data type. However, it provides the float type that behaves the same and has the same precision as doubles in C, C++, or Java. To convert …

How to Convert a String to a Double in Python? Read More »

What Are Differences Between type() and isinstance()?

The main difference between type() and isinstance() is that type(object) returns the type of an object and isinstance(object, class) returns True if the object argument is an instance of the class argument or in a direct or indirect subclass relationship. To strengthen your understanding, let’s quickly recap the syntactical definitions of both functions: type(object) โ€“ …

What Are Differences Between type() and isinstance()? Read More »

How to Limit Floats to Two Decimal Points in Python?

Introduction Problem Formulation: Given a floating-point value. How to limit it to two decimal places in Python? Example: Let’s have a look at a program where you have to calculate the value of pi. Output: Perfect! pi yields you a value = 3.141592653589793. But, what if you need the value of pi only up to …

How to Limit Floats to Two Decimal Points in Python? Read More »