Getting Started with Python: Basics with examples, debugging, errors, exceptions, database handling , interacting with system & more by Hemant Sharma
Author:Hemant Sharma [Sharma, Hemant]
Language: eng
Format: azw3, epub
Published: 2019-01-26T16:00:00+00:00
Multiple parameters
The parameters in function call are evaluated from left to right and associated with variables in that order.
Following example defines three parameters and calculated the volume of the object.
>>> length=2
>>> width=4
>>> height=5
>>> def getvol(length,width,height):
... print “volume is “, a*b*c
...
>>>
>>> getvol(length,width,height)
volume is 40
>>>
User input
If you working on a interactive program which need user input, it can be defines as in following example:
>>
>>> height = input("Enter Height ")
Enter Height 3
>>> width= input("Enter Width ")
Enter Width 4
>>> length= input("Enter Length ")
Enter Length 5
>>>
>>> getvol(length,width,height)
volume is 60
Using data from another function
As mentioned earlier, function data sharing is hierarchical to share data from one function to another, define the called function with parameter, it can be any name, doesn’t have to be same name as shared.
In the example below a topfunc() is define which sets the value of x, second function midfunc() is define inside which takes x as parameter and print its value.
>>> def topfunc():
... x = 10 ## set the value of x
... def midfunc(x): ## second function takes x as argument
... print “printing from mid function”, x
... midfunc(x) ## call to mid function to print value
...
>>> topfunc()
printing from mid function 10
>>>
A more convinent way do this is to use functions under the scope of main function.
Function Value Return
Function can return a value using return statement in a function. Python does not let any function without a return value, even if a function doesn’t return anything. You will see “None” as returned value.
In all the function examples above a value is returned when a function is called. This value can be used for display or further processing in the program.
>>> def test(a,b):
... c=a*b
... return 'DONE'
... print c
...
>>>
>>> test(a,b)
'DONE'
>>>
Only return value is printed as it returned before the print command, anything to print or return value must be stated before return statement.
Specialized built in Functions – filter, map and reduce
filter()
filter is a built in function which prints the values based on a condition. It takes two arguments
Function – which evaluate a condition and return true or false status.
Iterator , a range , list or tuple to go over
Download
Getting Started with Python: Basics with examples, debugging, errors, exceptions, database handling , interacting with system & more by Hemant Sharma.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9911)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9794)
The Mikado Method by Ola Ellnestam Daniel Brolund(9775)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8292)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7775)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7758)
Grails in Action by Glen Smith Peter Ledbrook(7693)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6782)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6509)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6377)
Kotlin in Action by Dmitry Jemerov(5061)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4315)
Functional Programming in JavaScript by Mantyla Dan(4037)
Solidity Programming Essentials by Ritesh Modi(3975)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3761)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3704)
The Ultimate iOS Interview Playbook by Avi Tsadok(3679)
