top of page

Python Tutorial

Public·1 member

Most Useful Built-in Functions in Python

abs(x): Return the absolute value (positive value ) of a number.

The argument (x) may be :

  • An integer or

  • A floating point number.

  • A complex number


If the argument is a complex number, its magnitude is returned.


Example 1: abs(x) of integer

x = -10
abs(x)

Output: 10


Example 2: abs(x) of float

x = -10.56
abs(x)

Output: 10.56


Example 2: abs(x) of complex number

x = 5
y = 3
# converting x and y into complex number 
z = complex(x,y)
print(z)

Output: (5+3j)


abs(z)

Output: 5.830951894845301


magnitude of z = sqrt ( 5 * 5 + 3 * i * 3 * i )

= sqrt( 25 + 9 * (i * i) )

= sqrt(25 + 9 * 1)

= sqrt(34)

= 5.830951894845301


all(iterable): Return True if all elements of the iterable are true (or if the iterable is empty).


x = [True, False, False]
y = [True, True, True]
print(all(x))
print(all(y))

Output:

False

True


any(iterable): Return True if any element of the iterable is true. If the iterable is empty, return False.

x = [True, False, False] 
y = [True, True, True] 
print(all(x)) 
print(all(y))

Output:

True

True




18 Views
bottom of page