DocScanner 8 Dec 2023 2-00 PM
DocScanner 8 Dec 2023 2-00 PM
WITH
WORKING
Chopter 3: Sample Code 2.2 (Contd....)
Environment For
Memory
38100
(1) 364 380 0
(2) 348
332
316
4 5
2 3 At line7, statement
myList.remove(s) removes element
5 from list and thus only three
6-L Global Environment elements are left in List(myList).
list
sau But the memory address of the
List1 Local Environment the same even
(myFunc3( )) (myList) remains
myList after changes in its contents.
same
The environment remains the
till line 9 and then control
returns to
line13.
3 4 5 6
1 2
Sams
Cest
a
Passing a Mutable Type Value to function
- Assigning parameter to a new valuelvariable.
:
1. def
my
List)
Func4 (my
now")
2. print ("\n\t Inside CALLED Function
3. print (" \t List received: ", myList)
new =
[3,5] a new value (a list here)
Parameter list get assigned
5. myList = new
9. List1 = [1, 4]
10. print ("List before function call :",
List1)
11. myFunc4( List1)
L2. print ("\nList after function call
:", Listl1)
COMPUTER SCIENCE
above Code
as
shown below: Chapter 3:
produced by
outpul Mernory
130
carefully look at the
Now [1, 4] (1)
(1) (1)
532 548 564 580 596 612 40116
9-10 1 2 3 4 6
1 of list referD
Lines Elements 0 and they hod
addresses of values
Global Environment
List1 9.10ofat
Till Lines 6-8
main
of Lines
(1)
532 (1)
580
1-3
12 3 4 5 6
40116
11,
Lines
nct 12
line10 agu Line
List1 At ed
COMPUTER SCIENCE WITH
ChodDoint that
3.1 > Changes in immutable types are not reflected in t
:
def processNumber (x)
=
X
72
return x +3
y= 54
res = processNumber (y)
Identify these parts : function header, function call, arguments, parameters, function body, main program
Solution.
:
Function header def processNumber (x)
Function call processNumber (y)
Arguments y
Parameters X
Function body X = 72
return x + 3
y = 54
Main program
res = processNumber (y)
ant : [CBSE 2020C)
J. Find and write the output of the following python code
if M[i]%5
M[i]//= 5
== 0 :
if M[i]%3
M[i]//= 3
L=[ 25,8,75, 12]
ChangeVal (L,4)
for i in L:
print (i, end ='#')
Solution. 5#8#5#4#
are called function variables
136 function header
parentheses of a
vithin the statement of_main segment.
4. Variables
that are listed begins with first
program execution
the function call. prOvided for that parameter 1:
5. In Pvthon skipped in
parameters cannot be
only if no value is
6 Detault parameters are
considered in
values for
7 The default
call statement.
the tunction values.
may return multiple
pvthon tunction to its caller.
8A returns a value ie., None
void function
A
also scope.
9
functions can have global
inside
10 Variables defined
name as that of global
a variable, hides the global variable in itsfuncion
having the same
11 A
lxal variable
AsSERTIONS AND REASONS
DIRECTIONS
(A) is followed by a statement of Reason (R)
In the folloeing questions, a statement of Assertion
Mark the correct choice as
:
Python (a) B
GEL (b) L E G B (c) GEBL (d) L BEG
call a ?
(Term 1 18. Which of the given argument types can be skipped from function
(b) keyword arguments
(a) positional arguments
(d) default arguments
(c) named arguments
FILL IN THE BLANKS