PWP UNIT 3
PWP UNIT 3
Patil(Python 314004)
UNIT III
What is Function :
Function is a block of instructions that performs a specific and well defined task.
This block can be repeatedly called by other programming instructions.
Every function specified by its name.
4.1 Use of Python built-in functions :
The built-in Python functions are pre-defined by the python interpreter. There are 68 built-in python
functions. These functions perform a specific task and can be used in any program, depending on
the requirement of the user.
The pre-defined built-in function of the python programming language is given below:
1) Python abs() : this function is used to generate the absolute value of a number
2) Python all() : This python returns true when all the elements in iterable are true
3) Python any() : This method is used to check if any Element of an Iterable is True
4) Python ascii()Returns String Containing Printable Representation
5) Python bin()this function is used to convert an integer to the equal binary string
6) Python bytes()the method is used to return an immutable bytes object
7) Python chr() From an Integer, this function returns a Character (a string).
8) Python classmethod()for a given function, returns the class method
9) Python enumerate()Returns an Enumerate Object
10) Python float()returns floating-point number from number, string
11) Python format() returns a formatted representation of a value
12) Python getattr() returns the value of an object’s named attribute
13) Python int() from a number or string, returns an integer
14) Python len() Returns Length of an Object
15) Python map() Applies Function and Returns a List
16) Python max() returns the largest item
17) Python min() returns the smallest value
18) Python next()Retrieves next item from the iterator
19) Python open()Returns a file object
20) Python ord() returns an integer of the Unicode character
21) Python pow()returns the power of a number
22) Python print()Prints the Given Object
23) Python property()returns the property attribute
24) Python range()between start and stop, return a sequence of numbers
25) Python reversed()returns the sequence’s reversed iterator
26) Python round()rounds a number to specified decimals
27) Python str()returns the string version of the object
28) Python sum()Adds items of an Iterable
29)Python super()Returns a proxy object of the base class
Ms
Ms.S.S.Patil(Python 314004)
Function Definition :
Every Function Should start with def Keyword.
Every function should have name (not equal to any keyword)
Example :
Function calling :
To call a defined function, just use its name as a statement anywhere in the
code.
When function is called the program control jumps to the definition of the
function and executes the statements present in the function body.
Example :
def Message(name):
print ('Hello ', name)
Example :
def Message(name:str):
print ('Hello ', name)
Ms
Ms.S.S.Patil(Python 314004)
Default Arguments :
Python supprts default argumentsin function. Default arguments are written using
assignment (=) operator.
Example :
Message('Ram')
Return Statement :
Ms