![]() |
name 'fullname' is not defined - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: name 'fullname' is not defined (/thread-12492.html) |
name 'fullname' is not defined - witch - Aug-27-2018 class Person: def __init__(self, first, last, fathers_name, age): self.first = first self.last = last self.fathers_name = fathers_name self.age = age def fullname(self): return '{} {} {}'.format(self.first, self.last, self.fathers_name) class Student(Person): def __init__(self, first, last, fathers_name, age, grade, avg_mark): super().__init__(first, last, fathers_name, age) self.grade = grade self.avg_mark = avg_mark class Workers(Person): def __init__(self, fisrt, last, fathers_name, age, positon, pay, wrk_exp): super().__init__(first, last, fathers_name, age) self.position = position self.pay = pay self.wrk_exp = wrk_exp person_1 = Person('Микола', 'Кучварський', 'Миколайович', 56) fullname(person_1) so I`m learning Python OOP and currently Im on classes, now I have this problem, any idea why it does it ?
RE: name 'fullname' is not defined - buran - Aug-27-2018 fullname is method of class Person, so you need to call it like this person1.fullname()you may want to print when call it print(person1.fullname())a bit advanced, would be to make it a property (not method). If it is too advanced, just ignore this for the moment @property def fullname(self): return '{} {} {}'.format(self.first, self.last, self.fathers_name)if you do so, you will access it like this person1.fullname RE: name 'fullname' is not defined - witch - Aug-27-2018 (Aug-27-2018, 02:45 PM)buran Wrote: fullname is method of class Person, so you need to call it like this Thanks you helped me a lot ! I appericate it ! |