0% found this document useful (0 votes)
2 views3 pages

PWP UNIT 3

The document discusses Python functions, including built-in functions and user-defined functions. It explains the structure of functions, how to define and call them, as well as the use of parameters and default arguments. Additionally, it provides examples to illustrate these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

PWP UNIT 3

The document discusses Python functions, including built-in functions and user-defined functions. It explains the structure of functions, how to define and call them, as well as the use of parameters and default arguments. Additionally, it provides examples to illustrate these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ms.S.S.

Patil(Python 314004)

UNIT III

Python Functions, Modules and Packages in Python

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)

4.2 User Defined Fuction :

 Function Definition :
 Every Function Should start with def Keyword.
 Every function should have name (not equal to any keyword)

Example :

def Message(): # Function Definition

print (“Hello World”) #statements

 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(): # Function Definition

print (“Hello World”) #statements

Message() # function calling

 Function Argument and Parameter Passing :


 Argumets are nothing but the inputs given to the particular user defined function
 It can have zero or more parameters.
 Every function with or without arguments should end with indentation
(:) Example :

def Message(name):
print ('Hello ', name)

Message('Ram') # calling function with argument Message(123)

Example :
def Message(name:str):
print ('Hello ', name)

Message('Ram') # calling function with string argument


Messaeg(123) # raise an error for int argument

Example for Multiple Parameters :


def greet(name1, name2, name3):

Ms
Ms.S.S.Patil(Python 314004)

print ('Hello', name1,' , ',name2 ,', and ', name3)

greet('Ram', 'Sham', 'Yash')


Example for Unknown Number of Arguments :
function in Python can have an unknown number of arguments by
putting * before the parameter if you don't know the number of
arguments the user is going to pass.
def greet(*names):

print ('Hello ', names[0], names[1], names[2])

greet('Ram', ‘Sham’, 'Yash')

Default Arguments :

Python supprts default argumentsin function. Default arguments are written using
assignment (=) operator.

Example :

def Message(name, College=”SVCP”):


print ('Hello ', name ,’from’ college)

Message('Ram')

 Return Statement :

Ms

You might also like