ниже код работает. < /p>
class Cars:
def __init__(self, make, model, year):
#Initialize the Car with specific attributes.
self.make = make
self.model = model
self.year = year
# Creating an instance using the parameterized constructor
car = Cars("Honda", "Civic", 2022)
print(car.make)
print(car.model)
print(car.year)
< /code>
output: < /p>
Honda
Civic
2022
Я пытаюсь отображать данные без использования __init __ . Мандат на использование?class Cars_class:
def Cars(self, make, model, year):
#Initialize the Car with specific attributes.
self.make = make
self.model = model
self.year = year
car=Cars("Honda", "Civic", 2022)
print(car.make)
print(car.model)
print(car.year)
< /code>
ошибка: < /p>
Traceback (most recent call last):
File "script.py", line 11, in
car=Cars("Honda", "Civic", 2022)
NameError: name 'Cars' is not defined
Подробнее здесь: https://stackoverflow.com/questions/794 ... -arguments
Python без использования аргументов использования ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение