user defined functions in python if you wont to download pycharm. now I start user defined functions in python
function: is a named sequence of statements that performs a computation.
So When you define a function, you specify the name
and the sequence of statements.
Later, you can “call” the function by name.
Python Support two types of function
- Inbuilt function: like len(), type, pow(), sqrt(), append() and many more.
- User defined function: which declare by user using def keyword.
A function is a group of related statements that
performs a specific task.
Syntax : def (parameter /argument list):
//body of function.
It is common to say that a function “takes” an
argument and “returns” a result. The result is called
the return value.
It is not mandatory that each function must have
parameter or argument list.
Again return is also not mandatory you can directly
print result in function body. but its good habit to
Type Conversion Function
The type conversion function is used to convert the data type
the function can convert floating-point values to
integers, but it doesn’t round off; it chops off the
fraction. As well as
int(3.99999) #Output 3
int(-2.3) #Output -2
float(): converts integers and strings to floating-point
float(32) # output 32.0
float(‘3.14159’) #output 3.14159
str() string function typecast the data or value into
It does not mean that it will give a character of value
65 or any other ASCII value. As well as
str(32) #output ’32’
str(3.14159) #output ‘3.14159‘
Python has a math module that provides most of the
familiar mathematical functions.
A module is a file that contains a collection of related
Before use the math module, we have to import it:
so When you import a package it will create a modulo
the object of that package which you imported. then
To access one of the functions, you have to specify
the name of the module and the name of the function,
separated by a dot (also known as a period). This
format is called dot notation.
Like math.pow(x,y) so here pow() is funciton name.
If you import package like,
also for more studies visit our website:-https://learningpoints.in/