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 6:58 ff the developer says:

https://www.youtube.com/watch?v=ZDa-Z5JzLYM&list=PL-osiE80TeTsqhIuOqKhwlXsIBIdSeYtc

the author 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.

well 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

    I suspect they're talking about the argument list names not having to match the object variable names you store them under, e.g. it could be:

    class Employee:
    
    def __init__(self, first, last, pay):
        self.first_name = first  # <-----
        self.last_name = last    # <-----
        self.email = first + '.' + last + '@email.com'
        self.pay = pay
    
    def fullname(self):
        return '{} {}'.format(self.first_name, self.last_name)
    

    But their recommendation is to keep them the same to enhance readability (and thus maintainability).

      Write a Reply...