Python Built-in Functions

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 »

How to Check Whether a Variable is a Class or Not?

This tutorial explores the ways one can check if a variable is a class. The direct way to check if a variable is a class, is to use the isclass() runtime service, from Python’s inspect module.  Use isclass() in conjunction with Python’s isinstance() built-in function, to examine a variable. Both of these return a Boolean …

How to Check Whether a Variable is a Class or Not? Read More »

How to Print a String Without ‘\n’ in Python

Strings, Printing and ‘\n’ The printing of a basic string is probably the first program the majority of people, myself included, write in Python –  does print(‘hello world’) sound familiar? From the outset we know the principle is simple, we can pass our string through the print() function and the output will be displayed in …

How to Print a String Without ‘\n’ in Python Read More »