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

5th Feb 2017, 4:08 AM
kavitha.k
14 Respostas
+ 4
It will remain same because you aren't updating my list
5th Feb 2017, 4:18 AM
Manthan Raja
Manthan Raja - avatar
+ 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
5th Feb 2017, 8:23 AM
visph
visph - avatar
+ 3
Finally! Same as my answer! :p
7th Feb 2017, 2:22 AM
Manthan Raja
Manthan Raja - avatar
+ 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
5th Feb 2017, 1:37 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 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
6th Feb 2017, 12:54 PM
kavitha.k
+ 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
6th Feb 2017, 3:27 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 1
ok and thanks don't leave words without knowing anything sry don't take in wrong manner .. I just said thts it
6th Feb 2017, 4:55 PM
kavitha.k
+ 1
here's the answer @kavitha there will not be any changes in mylist as the function is returning nothing.
6th Feb 2017, 8:29 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
@kavitha have you also joined the NPTEL course
5th Feb 2017, 6:17 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
no I didn't join nptel courses whts tht course @rishabh agrawal
5th Feb 2017, 9:38 AM
kavitha.k
0
this questions are given from my coll placement training teachers
5th Feb 2017, 9:39 AM
kavitha.k
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.
5th Feb 2017, 12:10 PM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
ooh okkk
5th Feb 2017, 1:03 PM
kavitha.k
0
can you send answer for tht
5th Feb 2017, 1:03 PM
kavitha.k