0
def mystery(l): l = l + l return() my list = [ 31,24,75] mystery (my list)
wht will the value of my list don't bother about indentation
14 Respuestas
+ 4
It will remain same because you aren't updating my list
+ 3
Do:
def mystery(l):
l.append(42)
# no need to use 'return' statement to return nothing
mylist = [31,24,75]
mystery(mylist)
print(mylist)
... will output: [31,24,75,42] as 'mysteriously' expected ;)
Or to add all the list:
def mystery(l):
for v in l:
l.append(v)
Attempting to assign a new value to 'l' variable, destroy the reference toward the array elements, but don't change the elements, so when the function terminate, the new created one is destroy, and the global 'mylist' is still unchanged... Modifying an element of the array inside the function will do the change in the global array reference, and 'append()' function modify also content ( by adding an item ) without creating new copy of the array ^^
And be aware of have same indentation in blocks, and spaces are not allowed in variable names :P
+ 3
Finally! Same as my answer! :p
+ 1
Well could you give me a single reason that i give you my assignment answers that too for your friend not for yourself.
@kavitha
+ 1
hey none of my frnds hve joined tht courses
thts my home work assignment from coll
I have to submit on Tuesday thts y I asked
don't be silly
@rishabh Agarwal
+ 1
okk but i will give you in tomorrow morning after due date has ended for the assignment, that way you will also be able to submit the assignment. Is that okay?
@kavitha
+ 1
ok and thanks
don't leave words without knowing anything
sry don't take in wrong manner ..
I just said thts it
+ 1
here's the answer @kavitha
there will not be any changes in mylist as the function is returning nothing.
0
@kavitha
have you also joined the NPTEL course
0
no I didn't join nptel courses
whts tht course
@rishabh agrawal
0
this questions are given from my coll placement training teachers
0
@kavitha
It's an online certification course for students and teachers and it is the assignment question to be submitted by tomorrow. So that's why i thought that.
0
ooh okkk
0
can you send answer for tht