overriding built-in __str__() method : Class str : Class PYTHON examples


PYTHON examples » Class » Class str »

 

overriding built-in __str__() method


 

class Employee:
    def __init__(self, lastname, firstname=None):
        self.lastname = lastname
        self.firstname = firstname

    def __str__(self):
        if self.firstname:
            return "%s %s" (self.firstname, self.lastname)
        else:
            return self.lastname

   
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Class
» Class str