dil_bert Posted January 24, 2018 Share Posted January 24, 2018 hello dear PHP-Freaks, well this seems to be a bit out of topic - but i want to dive into python so i have some beginner questions: in oo-development - lession classes and instances i have learned in this video: at in ff the developer says: now these don´t need to be the same as our arguments, so for example i could make thisself dot fname equals first, but usually i like to keep these similar if possible.so i am going to go ahad and set that back to self dot first equals first, okay? . end of citation. i wonder if it would be possible - to use other arguments than declarded class Employee: def __init__(self, first, last, pay): self.first = first self.last = last self.email = first + '.' + last + '@email.com' self.pay = pay def fullname(self): return '{} {}'.format(self.first, self.last) emp_1.first = `Corey` emp_1.last = `Schafer` emp_1.email = `corey.schafer@company.com ` so te question is. Can we really go and write like so: emp_1.fname = `Corey` emp_1.lname = `Schafer` emp_1.email = `corey.schafer@company.com ` but isn t this a lack of consistency? love to hear from you. greetings 1 Quote Link to comment https://forums.phpfreaks.com/topic/306319-python-classes-and-instances-how-to-treat-this/ Share on other sites More sharing options...
requinix Posted January 24, 2018 Share Posted January 24, 2018 What he's saying is that the "first" and "last" from the constructor def __init__(self, first, last, pay):don't have to be the same name as the "first" and "last" on the object self.first = first self.last = lastUsing "fname" and "lname" would be def __init__(self, first, last, pay): self.fname = first self.lname = last self.email = first + '.' + last + '@email.com' self.pay = payThat's allowed, Python doesn't care, but a human like me would read the code and think "why is one pair called first/last and the other called fname/lname"? It's odd. 2 Quote Link to comment https://forums.phpfreaks.com/topic/306319-python-classes-and-instances-how-to-treat-this/#findComment-1555730 Share on other sites More sharing options...
dil_bert Posted January 30, 2018 Author Share Posted January 30, 2018 good evening dear requinix, many thanks for the clearing. That's allowed, Python doesn't care, but a human like me would read the code and think "why is one pair called first/last and the other called fname/lname"? It's odd. you ve shed a ligth onto this issue. Thanks for helping me - here and so many times in other questions. KEEP up the superb work - this forum is such a great place. Greetings dil_bert Quote Link to comment https://forums.phpfreaks.com/topic/306319-python-classes-and-instances-how-to-treat-this/#findComment-1555883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.