class Mobile:
def __init__(self, model, type, year):
self.model = model
self.type = type
self.year = year
mobilePhones = [
["Samsung", "Galaxy S8", "2000"],
["Samsung", "Galaxy S9", "2001"],
["Samsung", "Galaxy S10", "2002"],
["Apple", "iPhone 8", "2005"],
["Apple", "iPhone 10", "2006"],
["Apple", "iPhone 11", "2007"],
]
phones = [
Mobile(mobilePhones[0][0],mobilePhones[0][1],mobilePhones[0][2]),
Mobile(mobilePhones[1][0], mobilePhones[1][1], mobilePhones[1][2]),
Mobile(mobilePhones[2][0], mobilePhones[2][1], mobilePhones[2][2]),
Mobile(mobilePhones[3][0], mobilePhones[3][1], mobilePhones[3][2]),
Mobile(mobilePhones[4][0], mobilePhones[4][1], mobilePhones[4][2]),
Mobile(mobilePhones[5][0], mobilePhones[5][1], mobilePhones[5][2]),
]
print(phones.model)
Мне просто интересно, почему этот лог c не работает? Я пытаюсь добавить все данные из 2dlist в класс, чтобы я мог вызывать все модели, типы или год.
print(mobilePhones[0][1])
работает, но не тогда, когда я пытаюсь вызвать его из класса , Нравится:
print(phones.model) or print(phones.year).