Jump to content

Recommended Posts

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 this
self 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

  • Like 1

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 = last
Using "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 = pay
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.
  • Like 2

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.