0% found this document useful (0 votes)
5 views1 page

Python Functions: Built-in & User Defined

The document discusses various types of functions in Python, including built-in functions from the math and random modules, which do not require importing. It explains how to define user-defined functions using the 'def' keyword and provides an example of a function for calculating simple interest. Overall, it highlights the importance of functions in programming for code reusability and organization.

Uploaded by

darkflux514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Python Functions: Built-in & User Defined

The document discusses various types of functions in Python, including built-in functions from the math and random modules, which do not require importing. It explains how to define user-defined functions using the 'def' keyword and provides an example of a function for calculating simple interest. Overall, it highlights the importance of functions in programming for code reusability and organization.

Uploaded by

darkflux514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Science

Enter any number100


Square Root value = 10.0
square value = 10000.0
The functions available in math module are:
ceil() floor() fabs() exp() log() log10() pow() sqrt() cos() sin() tan() degrees() radians()
Some functions from random module are:
random() randint() uniform() randrange()
2. Built in Function:
Built in functions are the function(s) that are built into Python and can be accessed by Programmer.
These are always available and for using them, we don't have to import any module (file). Python has a
small set of built-in functions as most of the functions have been partitioned to modules. This was done
to keep core language precise.
abs() max() min() bin() divmod() len() range() round() bool() chr() float() int() long() str( ) type( ) id( )
tuple( )
3. User Defined Functions:
In Python, it is also possible for programmer to write their own function(s). These functions can then be
combined to form module which can be used in other programs by importing them. To define a
function, keyword 'def' is used. After the keyword comes an identifier i.e. name of the function,
followed by parenthesized list of parameters and the colon which ends up the line, followed by the
block of statement(s) that are the part of function.
Syntax:
def NAME ([PARAMETER1, PARAMETER2, …..]):
#Square brackets include optional part of statement
statement(s)
Example: To find simple interest using function.
Example:
def SI(P,R,T):
return(P*R*T)
Output:
>>> SI(1000,2,10)
20000

You might also like