BUILT-IN-FUNCTION
IN PYTHON
By
MAADHESH P
I MCA
BUILT-IN
FUNCTION
The built-in function
are pre defined
functions, there are
68 Library function in
python, these
function perform a
Specific tasks and
can be used in
program.
abs() function
• The python abs() function used to return the
absolute value of a number.
• The argument can be integer and floating
point number.
• It takes only one argument, a number whose
absolute value is to be returned.
E x a m p l e :
a = - 2 0
p r i n t ( ‘ A b s o l u t e v a l u e o f - 2 0 i s : ’ , a b s ( a ) )
b = - 2 0 . 8 3
p r i n t ( ‘ A b s o l u t e v a l u e o f - 2 0 . 8 3 i s : ’ , a b s ( b ) )
O u t p u t :
Absolute value of -20 is: 20
Absolute value of -20.83 is: 20.83
bin() function
The python bin() function is used to return the
binary representation of a specific integer. A
result always starts with the prefix 0b.
E x a m p l e :
x = 1 0
y = b i n ( x )
p r i n t ( y )
O u t p u t :
0 b 1 0 1 0
bool() function
The python bool() converts a value to
Boolean (true or false) using the standard truth
Testing procedure.
E x a m p l e :
t e s t 1 = [ ]
p r i n t ( t e s t 1 , ’ i s ’ , b o o l ( t e s t 1 ) )
t e s t 2 = [ 1 ]
p r i n t ( t e s t 2 , ’ i s ’ , b o o l ( t e s t 2 ) )
O u t p u t :
[ ] i s f a l s e
[ 1 ] i s t r u e
sum() function
As the name says, python sum() function is
used to get the sum of numbers of an iterable.
E x a m p l e :
s = s u m ( [ 1 , 2 , 3 ] )
p r i n t ( s )
s 1 = s u m ( [ s ] , 1 0 )
p r i n t ( s 1 )
O u t p u t :
6
1 6
help() function
• Python help()function is used to get help
Related to the object passed during the call.
• It takes an optional parameter and returns
help information.
• It shows the python help console.It internally
calls python’s help function.
E x a m p l e :
i n f o = h e l p ( )
p r i n t ( i n f o )
O u t p u t :
W e l c o m e t o P y t h o n 3 . 1 !
T h i s i s t h e o n l i n e h e l p u t i l i t y .
len() function
The python len() function is used to return the
length (the number of items) of an object
E x a m p l e :
s t r A = ‘ P y t h o n ’
p r i n t ( l e n ( s t r A ) )
O u t p u t :
6
min() function
• Python min() function is used to get the
smallest element from the collection.
• This function takes two arguments, first is a
collection of elements and second is key, and
returns the smallest element from the collect.
E x a m p l e :
s m a l l = m i n ( 1 8 , 0 7 , 4 5 , 1 7 )
s m a l l 1 = m i n ( 1 8 . 2 5 , 1 8 . 2 4 , 1 8 . 2 3 )
O u t p u t :
0 7
1 8 . 2 3
pow() function
• The python pow() function is used to compute
the power of a number. It returns x to the
power of y.
• If the third arguments(z) is given, it returns x
to the power of y modules z.
E x a m p l e :
p r i n t ( p o w ( 2 , 3 ) )
p r i n t ( p o w ( - 2 , 3 ) )
p r i n t ( p o w ( 2 , - 3 ) )
p r i n t ( p o w ( - 2 , - 3 ) )
O u t p u t :
8
- 8
0 . 1 2 5
- 0 . 1 2 5
print() function
The python print() function prints the given
object to the screen or other standard output
devices.
E x a m p l e :
x , y, z = " a p p l e " , " b a n a n a " , " C h e r r y "
p r i n t ( x , y, z , s e p = ‘ , ’ , e n d = ‘ . ’ )
a = b = c = " a p p l e "
p r i n t ( a , b , c , s e p = ‘ , ’ , e n d = ‘ . ’ )
O u t p u t :
a p p l e , b a n a n a , C h e r r y .
a p p l e , a p p l e , a p p l e .
range() function
• The python range() function return as
immutable sequence of numbers starting from
0 by default.
• Increments by 1(by default) and ends at a
specified number.
E x a m p l e :
p r i n t ( l i s t ( r a n g e ( 0 ) ) )
p r i n t ( l i s t ( r a n g e ( 4 ) ) )
p r i n t ( l i s t ( r a n g e ( 1 , 7 ) ) )
O u t p u t :
[ ]
[ 0 , 1 , 2 , 3 ]
[ 1 , 2 , 3 , 4 , 5 , 6 ]
round() function
The python round() function rounds off the
digits of a number and returns the floating
point numbers.
E x a m p l e :
p r i n t ( r o u n d ( 1 0 . 4 ) )
p r i n t ( r o u n d ( 1 7 . 7 ) )
O u t p u t :
1 0
1 8
type() function
The python type() returns the type of the
specified object if a single argument is
passed to the type() built in function.
E x a m p l e :
l i s t 1 = [ 4 , 5 ]
p r i n t ( t y p e ( l i s t 1 ) )
d i c t 1 = { 4 : ’ f o u r ’ , 5 : ’ f i v e ’ }
p r i n t ( t y p e ( d i c t 1 ) )
O u t p u t :
< c l a s s ‘ l i s t ’ >
< c l a s s ‘ d i c t ’ >

Built-In-function python basics pre defined function

  • 1.
  • 2.
    BUILT-IN FUNCTION The built-in function arepre defined functions, there are 68 Library function in python, these function perform a Specific tasks and can be used in program.
  • 4.
    abs() function • Thepython abs() function used to return the absolute value of a number. • The argument can be integer and floating point number. • It takes only one argument, a number whose absolute value is to be returned.
  • 5.
    E x am p l e : a = - 2 0 p r i n t ( ‘ A b s o l u t e v a l u e o f - 2 0 i s : ’ , a b s ( a ) ) b = - 2 0 . 8 3 p r i n t ( ‘ A b s o l u t e v a l u e o f - 2 0 . 8 3 i s : ’ , a b s ( b ) ) O u t p u t : Absolute value of -20 is: 20 Absolute value of -20.83 is: 20.83
  • 6.
    bin() function The pythonbin() function is used to return the binary representation of a specific integer. A result always starts with the prefix 0b.
  • 7.
    E x am p l e : x = 1 0 y = b i n ( x ) p r i n t ( y ) O u t p u t : 0 b 1 0 1 0
  • 8.
    bool() function The pythonbool() converts a value to Boolean (true or false) using the standard truth Testing procedure.
  • 9.
    E x am p l e : t e s t 1 = [ ] p r i n t ( t e s t 1 , ’ i s ’ , b o o l ( t e s t 1 ) ) t e s t 2 = [ 1 ] p r i n t ( t e s t 2 , ’ i s ’ , b o o l ( t e s t 2 ) ) O u t p u t : [ ] i s f a l s e [ 1 ] i s t r u e
  • 10.
    sum() function As thename says, python sum() function is used to get the sum of numbers of an iterable.
  • 11.
    E x am p l e : s = s u m ( [ 1 , 2 , 3 ] ) p r i n t ( s ) s 1 = s u m ( [ s ] , 1 0 ) p r i n t ( s 1 ) O u t p u t : 6 1 6
  • 12.
    help() function • Pythonhelp()function is used to get help Related to the object passed during the call. • It takes an optional parameter and returns help information. • It shows the python help console.It internally calls python’s help function.
  • 13.
    E x am p l e : i n f o = h e l p ( ) p r i n t ( i n f o ) O u t p u t : W e l c o m e t o P y t h o n 3 . 1 ! T h i s i s t h e o n l i n e h e l p u t i l i t y .
  • 14.
    len() function The pythonlen() function is used to return the length (the number of items) of an object
  • 15.
    E x am p l e : s t r A = ‘ P y t h o n ’ p r i n t ( l e n ( s t r A ) ) O u t p u t : 6
  • 16.
    min() function • Pythonmin() function is used to get the smallest element from the collection. • This function takes two arguments, first is a collection of elements and second is key, and returns the smallest element from the collect.
  • 17.
    E x am p l e : s m a l l = m i n ( 1 8 , 0 7 , 4 5 , 1 7 ) s m a l l 1 = m i n ( 1 8 . 2 5 , 1 8 . 2 4 , 1 8 . 2 3 ) O u t p u t : 0 7 1 8 . 2 3
  • 18.
    pow() function • Thepython pow() function is used to compute the power of a number. It returns x to the power of y. • If the third arguments(z) is given, it returns x to the power of y modules z.
  • 19.
    E x am p l e : p r i n t ( p o w ( 2 , 3 ) ) p r i n t ( p o w ( - 2 , 3 ) ) p r i n t ( p o w ( 2 , - 3 ) ) p r i n t ( p o w ( - 2 , - 3 ) ) O u t p u t : 8 - 8 0 . 1 2 5 - 0 . 1 2 5
  • 20.
    print() function The pythonprint() function prints the given object to the screen or other standard output devices.
  • 21.
    E x am p l e : x , y, z = " a p p l e " , " b a n a n a " , " C h e r r y " p r i n t ( x , y, z , s e p = ‘ , ’ , e n d = ‘ . ’ ) a = b = c = " a p p l e " p r i n t ( a , b , c , s e p = ‘ , ’ , e n d = ‘ . ’ ) O u t p u t : a p p l e , b a n a n a , C h e r r y . a p p l e , a p p l e , a p p l e .
  • 22.
    range() function • Thepython range() function return as immutable sequence of numbers starting from 0 by default. • Increments by 1(by default) and ends at a specified number.
  • 23.
    E x am p l e : p r i n t ( l i s t ( r a n g e ( 0 ) ) ) p r i n t ( l i s t ( r a n g e ( 4 ) ) ) p r i n t ( l i s t ( r a n g e ( 1 , 7 ) ) ) O u t p u t : [ ] [ 0 , 1 , 2 , 3 ] [ 1 , 2 , 3 , 4 , 5 , 6 ]
  • 24.
    round() function The pythonround() function rounds off the digits of a number and returns the floating point numbers.
  • 25.
    E x am p l e : p r i n t ( r o u n d ( 1 0 . 4 ) ) p r i n t ( r o u n d ( 1 7 . 7 ) ) O u t p u t : 1 0 1 8
  • 26.
    type() function The pythontype() returns the type of the specified object if a single argument is passed to the type() built in function.
  • 27.
    E x am p l e : l i s t 1 = [ 4 , 5 ] p r i n t ( t y p e ( l i s t 1 ) ) d i c t 1 = { 4 : ’ f o u r ’ , 5 : ’ f i v e ’ } p r i n t ( t y p e ( d i c t 1 ) ) O u t p u t : < c l a s s ‘ l i s t ’ > < c l a s s ‘ d i c t ’ >