我只是想...但self.value顯示錯誤ie ...我想循環self.a,self.b,self.c ...需要幫助需要學習幫助。 .....輸出想要的是x = [AA,EE,II]使用類和loops.i嘗試循環self.a,self.b,self.c使用循環.........我正在學習Python和麪向對象編程新....幫我出python中的數組處理
import string
A = ["AA","BB","CC","DD"]
B = ["EE","FF","GG","HH"]
C = ["II","JJ","KK","LL"]
class User:
def __init__(self,A,B,C):
self.a= A
self.b= B
self.c= C
def User1(self):
x=[]
for i in range(ord('a'), ord('c')+1):
value= chr(i)
x.append= self.(value)[0] ///for getting first elemen from A,B,C
i+=1
return x
honey= User(A,B,C)
print(honey.User1())
'x.append = self。(value)[0]'沒有任何意義。要追加到列表中,您可以使用'x.append(value [0])'。你不能在這裏使用'self.value',因爲它不是一個實例屬性(或者事先將它定義爲'self.value = chr(i)')。 – roganjosh