python面向对象的编程类型:list对象不可调用

时间:2018-03-15 10:51:13

标签: python python-3.x function

class y():
    def __init__(self,favourite_channels = [""]):

        self.favourite_channels= favourite_channels
    def favourite_channels(self,i):
        print("Ur Favourite Channel=",i)
        self.favourite_channels.append(i)
x = y()
print("""*******************

1. Favourite Channel
press q to the exit
*******************""")

while True:

    a = input("Select : ")
    if a=="1":
        channels=input("Your fav channels use , to the split")
        addable_channels =channels.split(",")
        for i in addable_channels:
            x.favourite_channels(i)


    elif a=="q":
        break
    else:
        print("İnvalid Number")

1 个答案:

答案 0 :(得分:0)

如果你支持列表的末尾(x.favourite_channels是列表),那么你会得到这样的错误。 如果你想要列表x.favourite_channels的元素,你应该写x.favourite_channels [i-1]。