Reputation: 19
i am trying my first code in python writing classes and objects..
here is the code:
class Order:
def __init__(self,A):
self.a= A
def user1(self):
x = len(self.a)
i =0
while i < x:
value = A[i]
y = value
return y
A = ["AA","BB","CC","DD","EE","FF"]
honey= Order(A)
print (honey.user1())
i am getting output as AA................but i need to all elements from the A[] ,so only wrote for loop...but it print only output as AA.......
I need output as AA BB CC DD EE FF
how to achieve it using classes and object creation.....help pls
Upvotes: 1
Views: 12742
Reputation: 28
what you doing is returning after it loops and gets the first value and thus it gives back only the first value
Also, you are not incrementing your loop this will result in an infinite loop.
something like this is what it should be:
y=[]
while i < x:
value = A[i]
y.append(value)
i+=1
return y
Upvotes: 1