Python | ldexp() function Last Updated : 14 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report ldexp() function is one of the Standard math library function in Python, which returns x * (2**i). This is also called as inverse of Python frexp() function. Syntax: math.ldexp(x, i) Parameters: x : Any valid number (+ve or -ve) i : Any valid number (+ve or -ve) Returns : Returns the value of x * (2**i). Time Complexity: O(1) Auxiliary Space: O(1) For example, if x = 3 and i = 4 then, Math.ldexp(3, 4) = 3*16 = 48. Code #1: Python3 # Python3 code demonstrate ldexp() function # importing math library import math # ldexp() Function on +ve nd -ve Numbers print(math.ldexp(9, 3)) print(math.ldexp(-5, 2)) # ldexp() Function on fractional Number print(math.ldexp(3.5, 2)) print('%.2f' %math.ldexp(-6.8, 3)) Output: 72.0 -20.0 14.0 -54.40 Code #2: Python3 # Python3 code demonstrate ldexp() function # importing math library import math # Tuple Declaration tpl = (9, -5, 3.5, -6.8) # List Declaration lst = [13, 4, 8.4, -6.7] # ldexp() Function on +ve nd -ve Numbers print(math.ldexp(tpl[0], 3)) print(math.ldexp(tpl[3], 2)) # ldexp() Function on fractional Number print(math.ldexp(lst[1], 2)) print('%.2f' %math.ldexp(lst[2], 3)) Output: 72.0 -27.2 16.0 67.20 Code #3: If the X value or i value argument is not a number, ldexp() function will return TypeError. Python3 # Python3 code demonstrates when error occurs # importing the math library import math # string value taken print(math.ldexp('25', 5)) print(math.ldexp(25, '5')) Output: TypeError: a float is required TypeError: a float is required Comment More infoAdvertise with us Next Article ord() function in Python J jana_sayantan Follow Improve Article Tags : Python Python-Library Python-Built-in-functions Python math-library Python math-library-functions +1 More Practice Tags : python Similar Reads Python print() function The python print() function as the name suggests is used to print a python object(s) in Python as standard output. Syntax: print(object(s), sep, end, file, flush) Parameters: Object(s): It can be any python object(s) like string, list, tuple, etc. But before printing all objects get converted into s 2 min read Python Functions Python Functions is a block of statements that does a specific task. The idea is to put some commonly or repeatedly done task together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over an 9 min read ord() function in Python Python ord() function returns the Unicode code of a given single character. It is a modern encoding standard that aims to represent every character in every language.Unicode includes:ASCII characters (first 128 code points)Emojis, currency symbols, accented characters, etc.For example, unicode of 'A 2 min read Python - globals() function In Python, the globals() function is used to return the global symbol table - a dictionary representing all the global variables in the current module or script. It provides access to the global variables that are defined in the current scope. This function is particularly useful when you want to in 2 min read cmp() function - Python cmp() method in Python 2.x compares two integers and returns -1, 0, 1 according to comparison. cmp() does not work in python 3.x. You might want to see list comparison in Python.ExamplePython# Example 1 print(cmp(3, 4)) # Example 2 print(cmp(5, 5)) # Example 3 print(cmp(7, 6)) Output-101ExplanationI 3 min read dir() function in Python The dir() function is a built-in Python tool used to list the attributes (like methods, variables, etc.) of an object. It helps inspect modules, classes, functions, and even user-defined objects during development and debugging.Syntaxdir([object])Parameters: object (optional): Any Python object (lik 3 min read Like