python - Iterating on return object -
this question has answer here:
- return statement in loops 6 answers
i trying oop python. need iterating values in objects defined for
loop, call function process_test()
, loop stops return object.
how can make function process_test()
create objects , assign values of i
on on each loop?
class test(object): abc = 0 cde = 0 def process_test(): in xrange(5): # print myobj = test() myobj.abc = #print myobj.abc return myobj.abc myobj = process_test() print myobj
output:
0
desired output:
0 1 2 3 4 5
when first return function, no longer in function. need store value in list, return it
class test(object): abc = 0 cde = 0 def process_test(): l = [] in xrange(6): # print myobj = test() myobj.abc = #print myobj.abc l.append(myobj.abc) return l myobj = process_test() x in myobj: print x
hope, help.
Comments
Post a Comment