Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

__new__ python

class Person:
    def __new__(cls, first_name, last_name):
        # create a new object
        obj = super().__new__(cls)

        # initialize attributes
        obj.first_name = first_name
        obj.last_name = last_name

        # inject new attribute
        obj.full_name = f'{first_name} {last_name}'
        return obj


person = Person('John', 'Doe')
print(person.full_name)

print(person.__dict__)
Code language: Python (python)
Comment

python __new__

__new__ is a static method
Comment

PREVIOUS NEXT
Code Example
Python :: python instagram bot 
Python :: python call function by string 
Python :: convert birth date column to age pandas 
Python :: Check if all values in list are greater than a certain number 
Python :: pandas .replace multiple values in column 
Python :: set default dictionary in python 
Python :: python elif syntax 
Python :: list comprehension in python 
Python :: python string to list without split 
Python :: using comma as the thousand separator 
Python :: math function in python 
Python :: ImportError: cannot import name 
Python :: return programming 
Python :: how to append data in excel using python pandas 
Python :: show chrome devtools in selenium 
Python :: python launch prompt 
Python :: tkinter triangle 
Python :: == in python 
Python :: Merge multiple dataframs 
Python :: dataframe partition dataset based on column 
Python :: python pandas change column order 
Python :: printing with format 
Python :: Reverse an string Using Reversed 
Python :: how to open link in new tab selenium python 
Python :: david dobrik 
Python :: how to make a time limit using renpy 
Python :: print [url_string for extension in extensionsToCheck if(extension in url_string)] 
Python :: python coding for y, you will also display a “bar” of ‘X’ characters to represent the number. For example, the prime number 2 would be represented as “X 2”. 
Shell :: bitnami restart apache 
Shell :: set default branch to main on git init 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =