0
keeplist1= ['GenderDesc','MartialStatusDesc','castegroup']
dummylist1= 'castegroup'

def funky(keeplist,dummylist):

        keeplist.remove(dummylist)
        print keeplist

funky(keeplist1,dummylist1)

output: ['GenderDesc', 'MartialStatusDesc']

print keeplist1

output: ['GenderDesc', 'MartialStatusDesc']

Both the print statements give the same output. Is this expected behavior?

thefourtheye
  • 221,210
  • 51
  • 432
  • 478
  • Briefly: scope isn't really involved. You just passed in and mutated a mutable object. – TigerhawkT3 Dec 29 '16 at 07:01
  • Yes that is expected behaviour..List elements can be changed inside a function. any changes made to list elements in a function can be reflected in a list which is outside of function. You can refer the question suggested by TigerhawkT3 – Teja Dec 29 '16 at 07:11

0 Answers0