Embed presentation





![© SkillBrew http://skillbrew.comCalling a Function6def printList():num_list = range(3)print num_listprintList()Output:[0, 1, 2]To call a function, we specify the function namewith the round bracketsCall to function](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-6-2048.jpg&f=jpg&w=240)
![© SkillBrew http://skillbrew.comreturn keyword7def printList():num_list = range(3)return num_listmy_list = printList()print my_listOutput:[0, 1, 2]1. The return keyword isused to return valuesfrom a function2. A function implicitlyreturns None by defaulteven if you don’t usereturn keyword](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-7-2048.jpg&f=jpg&w=240)
![© SkillBrew http://skillbrew.comParameterized functions8def printList(upper_limit):num_list = range(upper_limit)print "list: %s" % num_listprintList(5)printList(2)Output:list: [0, 1, 2, 3, 4]list: [0, 1]1. Names given in thefunction definitionare calledparameters2. The values yousupply in thefunction call arecalledarguments](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-8-2048.jpg&f=jpg&w=240)
![© SkillBrew http://skillbrew.comDefault arguments9def printList(upper_limit=4):print "upper limit: %d" % upper_limitnum_list = range(upper_limit)print "list: %s" % num_listprintList(5)printList()Output:upper limit: 5list: [0, 1, 2, 3, 4]upper limit: 4list: [0, 1, 2, 3]value 41. When function is calledwithout any arguments defaultvalue is used2. During a function call ifargument is passed then thepassed value is used](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-9-2048.jpg&f=jpg&w=240)

![© SkillBrew http://skillbrew.comKeyword arguments11def printList(upper_limit, step=1):print "upper limit: %d" % upper_limitnum_list = range(0, upper_limit, step)print "list: %s" % num_listprintList(upper_limit=5, step=2)Output:upper limit: 5list: [0, 2, 4]range() function has two variations:1.range(stop)2.range(start, stop[, step])](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-11-2048.jpg&f=jpg&w=240)











The document discusses the basics of functions in Python, including what a function is, the advantages of using functions, how to define and call functions, and how to use parameters, return values, global variables, default arguments, keyword arguments, and docstrings when working with functions. Key points covered include how functions allow code reuse and decomposition of complex problems, how to define a function using the def keyword, how to call a defined function by name, and how docstrings provide documentation for functions and other objects.





![© SkillBrew http://skillbrew.comCalling a Function6def printList():num_list = range(3)print num_listprintList()Output:[0, 1, 2]To call a function, we specify the function namewith the round bracketsCall to function](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-6-2048.jpg&f=jpg&w=240)
![© SkillBrew http://skillbrew.comreturn keyword7def printList():num_list = range(3)return num_listmy_list = printList()print my_listOutput:[0, 1, 2]1. The return keyword isused to return valuesfrom a function2. A function implicitlyreturns None by defaulteven if you don’t usereturn keyword](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-7-2048.jpg&f=jpg&w=240)
![© SkillBrew http://skillbrew.comParameterized functions8def printList(upper_limit):num_list = range(upper_limit)print "list: %s" % num_listprintList(5)printList(2)Output:list: [0, 1, 2, 3, 4]list: [0, 1]1. Names given in thefunction definitionare calledparameters2. The values yousupply in thefunction call arecalledarguments](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-8-2048.jpg&f=jpg&w=240)
![© SkillBrew http://skillbrew.comDefault arguments9def printList(upper_limit=4):print "upper limit: %d" % upper_limitnum_list = range(upper_limit)print "list: %s" % num_listprintList(5)printList()Output:upper limit: 5list: [0, 1, 2, 3, 4]upper limit: 4list: [0, 1, 2, 3]value 41. When function is calledwithout any arguments defaultvalue is used2. During a function call ifargument is passed then thepassed value is used](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-9-2048.jpg&f=jpg&w=240)

![© SkillBrew http://skillbrew.comKeyword arguments11def printList(upper_limit, step=1):print "upper limit: %d" % upper_limitnum_list = range(0, upper_limit, step)print "list: %s" % num_listprintList(upper_limit=5, step=2)Output:upper limit: 5list: [0, 2, 4]range() function has two variations:1.range(stop)2.range(start, stop[, step])](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fpythonprogrammingessentials-m17-functions-140819043207-phpapp01%2f75%2fPython-Programming-Essentials-M17-Functions-11-2048.jpg&f=jpg&w=240)









