您好,我正在创建一个包含购物清单的课程。该代码似乎有效,但我不确定我是否正确执行。我是否打算将 Shopping = [] 放入构造函数中,那有什么作用?提前谢谢了
class Shopping:
def __init__(self, shopping = []):
self.__shopping = []
def set_shopping(self, shopping):
self.__shopping = shopping
def get_shopping(self):
return self.__shopping
shoppinglist = Shopping()
shoppinglist = ['apples', 'pears', 'bread']
繁星淼淼
相关分类