# 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 …

## Python Print Without Parentheses

Parentheses are used to initiate a function call in Python. Here are three examples: f() calls custom function f without an argument, print(‘hello world’) calls built-in function print with the string argument ‘hello world’, and range(2, 10, 3) calls built-in function range on the integer arguments 2, 10, and 3. A common question among Python …

## 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 ‘ ‘ …

## 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, …

## 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 …

## 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) – …

## How to Round a Number Up in Python?

To round a number up in Python, import the math library with import math, and call math.ceil(number). The function returns the ceiling of the specified number that is defined as the smallest integer greater than or equal to number The following code shows how to round the number 42.42 up to 43. If you don’t …

## 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 …

## Python For Loop Inside Lambda

Problem: Given an iterable, how to print it using a for loop within a lambda function. Overview In this tutorial, we will learn why it is not a smart idea to use for loop inside Lambda in Python. This is a frequently asked question by programmers and newbies. Hence, it needs to be addressed as …

## Python Operators Overview

What Are Python Operators? Python operators are special syntactical sugar to run basic operations without calling their respective methods. For example, you can use the + operator in a + b instead of the more clunky .add() method in a.add(b). Each operator has a unique symbol that is placed between the two arguments called operands. …

## Python |= In-Place OR Operator

Have you stumbled upon the strange-looking Python operator A |= B in a code snippet and you don’t know what it means? This article will clarify it once and for all! Let’s start with the short answer: Python’s A |= B applies the | operator in place. Thus, it is semantically identical to the longer-form …

## How to Get the Size of a String in Python?

Problem Formulation: Given a string my_string. Find the number of characters of the string! For example, the string “what is my length?” must yield integer 18 because it has 18 characters. Here are three examples of our desired outputs: Solution: Before we dive into alternatives, here’s the quick answer to this question. To get the …