Here is class 12 computer science Unit 3 [Type A] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 3 and for all chapters here.Watch all tutorials for chapter 3: Python Revision Tour.
A program having multiple function satisfy the following parameter :1. Increase reusability of code.2. Decrease the complexity of the program.3. Clean and understandable structure of programme increases.4. Ease of debugging of program.
Flow of execution refers to flow in which the statement are executed in the program i.e. generally top to bottom during execution.Function definition do not alter this order and the function is not taken into account of the execution till the function is called in the program.
return result # after this next line of function call is executed
function_name(parameter) # direct to function definition
Argument is the keyword that is related to the time of function calls. Argument need to be provided while calling a function. For example calling an addition function need to pass two value to add and these values are called arguments.Sum(5, 4) # here 5 and 4 is termed as argument.
Parameter is the keyword related to the function definition. Its defines the requirement of the values and type of that to act upon the function.def Sum(a, b): # here a and b is named parameter
Hence, we can say that argument is values of parameter while calling a function.
(i) Default argument allows us to have safe end with function calling and also a standard parameter tuning while function definition. If the function is called without the argument, the argument gets its default value that is defined during function definition.
(ii) Keyword arguments in python is one of the method of parameter allocation after the positional arguments. It makes a more easy way of parameter value allocation by the naming of parameter.Keyword arguments are included with a keyword and equals sign.
# Function definition is here
def Person(name, age = 35 ): #age default argument
print "Name: ", name
print "Age ", age
# Now calling function
Person(age=50, name="Vishal") #keyword argument
Person(50, "Vishal") # keyword argument is not used
As during the definition of function we defined age as 35 i.e. we defined a default value to age and this is termed as default argument. Such as during calling of function :Case 1: No argument to age is passed hence default value 35 assigned to age.Case 2: Age is given argument value 50, hence it will overlap default value 35.Case 3: In this the function is called without the keyword argument.
There are basically three type of function in python Built-in–function : These are globally defined function and always ready to use in python itself. For example len(), range(), type(), int() etc.Module function : These are the function that are defined under specific module. To use then import of the module is important. For example : sum(), sqrt() in Math module, plot(), scatter() in matplotlib etc.User Defined : These are the function that are defined by the user during the course of the program for specific use.
There are basically three type of function in python
Built-in-function : These are globally defined function and always ready to use in python itself. For example len(), range(), type(), int() etc.
Module function : These are the function that are defined under specific module. To use then import of the module is important. For example : sum(), sqrt() in Math module, plot(), scatter() in matplotlib etc.
User Defined : These are the function that are defined by the user during the course of the program for specific use.
Yes, function in python can return multiple values easily in different form like as object, list, tuple, dictionary.
def swap(a, b):
a, b=b, c
def swap(a, b):
a, b=b, c
The above code is for return multiple value by list.
The part of program where data or code (variable) can be accessed is called scope of variable in python.
The scope resolution rule in python is known as LEGB rule i.e. Local, Enclosing, Global, Built-in. The two mainly are local and global scope.
A local variable is just being access under the block of scope while the global variable can be assessed in the entire program.
def swap(a, b):
a, b = b, c
return [a, b]
res = swap(3,4)
Here an is global variable hence print(a) will run but c is local variable that is access under swap function block that’s why print(c) will show error.
Global statement is refers to the global variable that can be used in entire program and hence is used to get rid of again and again defining and increase reusability. Such as we defined pi =3.14 as globally to have same value in entire program.
It is not highly recommended because there can instance occur when global and local statement having same name then it will manipulate actual result of program.
(a) Function declared argument.(b) Keyword argument.(c) Formal parameter.(d) Default argument.(e) Actual parameter.(f) Global variable.(g) Local variable.
Clear Doubts with Computer TutorIn case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in
You cannot copy content of this page