Question

In: Computer Science

How does a value-returning function differ from the void functions? in pyhton

How does a value-returning function differ from the void functions? in pyhton

Solutions

Expert Solution

NOTE :

INDENTATION IS ONE OF THE MAJOR ISSUE OF PYTHON PROGRAMMING. IF THERE IS ANY PROBLEM IN INDENTATION, KINDLY REFER TO THE SCREEN SHOTS OF THE PROGRAMS, BELOW THE TEXT BASED SOURCE CODES. AS SCREEN SHOT IS IMAGE BASED , SO THE INDENTATION IS SHOWN PERFECTLY IN SCREEN SHOT. IF REQUIRED, CAN REFER THE INDENTATION FROM SCREEN SHOTS AND MODIFY THE PROGRAM SOURCE CODES.THE CODES ARE GIVING EXACT OUTPUT.

Value returning function:

The function which returns any value, is called value returning function.

Void function:

The function which does not return any value is called void function

i. Syntax of function defining section of value returning function and void function are same in python.

ii. But the difference is :

Value returning function:

a. The value returning function of python returns value with keyword return.

b. The returned value is stored in called function and it can be used further.

             Void function:

a. Void function does not return any value.

b. The calling function only calls the function. At function definition part entire operation is performed and result is generated.

Here in the example:

i. addition as value returning function, returns s, which is stored in res variable through calling function addition(lst) and print the value of res as final result.

ii. Addition in void type function in second program, calculate s and print the result of s in function definition part, where s is not returned in function calling part.

VALUE RETURNING FUNCTION :

# function retuns value
def addition(l):
s=0.0;
# add all values of list l
for i in range(0,len(l)):
s=s+l[i]
# returing value of s
return s
  
  
lst=[4,5,6,7,8,9,12,13,19];
# called function addition store the returned value of s of addition(lst) function
#here addition(lst) is value returning function
res=addition(lst)
# print the result
print('Addition result is : ' ,res)

SCREEN SHOT

OUTPUT

VOID TYPE FUNCTION :

# function retun type is void
def addition(l):
s=0.0;
# add all values of list l
for i in range(0,len(l)):
s=s+l[i]
# print the result
print('Addition result is : ' ,s)
  
  
lst=[4,5,6,7,8,9,12,13,19];
#addition(lst) function is called here
# here addition(lst) is void function
addition(lst)

SCREEN SHOT

OUTPUT


Related Solutions

What is a VOID function? How do local and global variables differ? Explain how the value-return...
What is a VOID function? How do local and global variables differ? Explain how the value-return function works.
What are the functions of the plasma membrane? How does the function differ between bacteria and...
What are the functions of the plasma membrane? How does the function differ between bacteria and eukaryotic cells? How does DNA differ between bacteria and eukaryotic cells? What is the function of ribosomes? What is the composition of ribosomes? How does it differ between prokaryotes and eukaryotes? What is a cytoplasm? What are the 2 main classes of reactions in cells? What is the energy currency of cells? Why? Be able to explain this in terms of structure. What is...
Describe how a LASER functions. How does a LASER differ from a continuum source? a brief...
Describe how a LASER functions. How does a LASER differ from a continuum source? a brief description of each of the four steps of lasing.  
a) Describe value creation on platforms. How does such value creation differ from value creation in...
a) Describe value creation on platforms. How does such value creation differ from value creation in traditional organisations? (500 words) b) Use a platform of your own choice to illustrate how value creation occurs on digital platforms. (300 words)
How does the structure & function of the circulatory system in a fetal mammal differ from...
How does the structure & function of the circulatory system in a fetal mammal differ from that of the adult mammal? a. Where is fetal blood oxygenated and what is the pathway of oxygenated blood to the fetal heart? b. How does the structure of the fetal heart and the blood flow through the fetal heart differ from the adult?
How does bank regulation differ from bank supervision? What are the main roles and functions of...
How does bank regulation differ from bank supervision? What are the main roles and functions of bank regulators? Discuss.
How does funds statement differ from the functions of the balance sheet, income statement and statement...
How does funds statement differ from the functions of the balance sheet, income statement and statement of cash flows?
4) a) Describe value creation on platforms. How does such value creation differ from value creation...
4) a) Describe value creation on platforms. How does such value creation differ from value creation in traditional organisations? b) Use a platform of your own choice to illustrate how value creation occurs on digital platforms.
1 Describe value creation on platforms. How does such value creation differ from value creation in...
1 Describe value creation on platforms. How does such value creation differ from value creation in traditional organisations? 2 Use a platform of your own choice to illustrate how value creation occurs on digital platforms
1) How does a bailment differ from a gift? 2) How does a bailment differ from...
1) How does a bailment differ from a gift? 2) How does a bailment differ from a lease? 3) Give an example of a bailment that is not a contract. Give an example of a bailment that is a contract.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT