Some important basic in – built functions in python

As there are many in-built functions in python which helps us in competitive programming and saves our time in writing code for those functions.

In this python tutorial, we are going to discuss some basic in-built functions in python.

abs() function in Python

abs() function is python is used to return the absolute value of integer number, floating point number or complex number.

   Syntax :- abs(number)

value for which we want absolute value is passed as parameter in function abs().

 Python code to implement in-built abs() function

a = -1.2 

    print('Absolute value of a is:', abs(a))

 b = -6 

    print('Absolute value of b is:', abs(b))

 c = (4 - 3j) 

     print('Magnitude of c is:', abs(c))

OUTPUT 

('Absolute value of a is:', 1.2)
('Absolute value of b is:', 6)
('Absolute value c is:', 5.0)

pow() function in Python

pow() function in python is used to compute the power of a number. It has many applications in day to day programming.

    Syntax :- pow(x,y)

x: Number whose power has to be calculated.

y: Value raised to compute power.

Returns the value x**y.

Implementation Cases in pow()

1.) If both the values are non-negative, the return type is an integer.

2.) If x is non-negative and y is negative, then return type is a float.

3.)  If x is negative and y is non-negative, then return type is an integer.

4.) If x is non-negative and y is non-negative, then return type is a float.

Python code to implement in-built pow() function

print ("The value of 8**7 is : ",end=" ") 

    print (pow(8,7)) 

print ("The value of 8**-7 is : ",end=" ") 

    print (pow(8,-7))

print ("The value of -8**7 is : ",end=" ") 

    print (pow(-8,7))

print ("The value of -8**-7 is : ",end=" ") 

    print (pow(-8,-7))

OUTPUT

The value of 8**7 is: 2097152
The value of 8**-7 is : 4.76837158203125e-07
The value of -8**7 is: -2097152
The value of -8**-7 is : -4.76837158203125e-07

gcd() in Python

GCD ( Greatest Common Divisor ) also known as HCF ( High Common Factor ) of the two numbers is the greatest number which divides both numbers.

Header file used:- import math

Syntax :- math.gcd( a,b ) ;

where a,b are two numbers whose gcd is to find.

Python Code to implement in-built gcd() function

import math

a=int(input('Enter the first number\n'))

b=int(input('Enter the second number\n'))

print ('GCD of a and b is :' ,math.gcd(a,b))

 

INPUT

2
3


OUTPUT 

1

You may also read,

Leave a Reply

Your email address will not be published. Required fields are marked *