12/05/2022

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

  1. Inbuilt function: like len(), type, pow(), sqrt(), append() and many more.
  2. 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
return result.

Type Conversion Function

The type conversion function is used to convert the data type
of value.

int()

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

int(‘Hello’) #Output

float(): converts integers and strings to floating-point
numbers.

float(32) # output 32.0

float(‘3.14159’) #output 3.14159

str() string function typecast the data or value into
string form.

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‘

Math functions

Python has a math module that provides most of the
familiar mathematical functions.

A module is a file that contains a collection of related
functions.

Before use the math module, we have to import it:

import math

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/

Leave a Reply

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