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 :: docker django 
Python :: iterate backwards through a list python 
Python :: pandas change column dtype 
Python :: convert timedelta to int 
Python :: python random geneator 
Python :: intersection() Function of sets in python 
Python :: redirect parameters flask 
Python :: python num2words installation 
Python :: python factorial 
Python :: list variables in session tensorflow 1 
Python :: How To Display A Background Image With Tkinter 
Python :: rest_auth pip 
Python :: with suppress python 
Python :: python dict get random key 
Python :: np.random.RandomState 
Python :: yaxis on the right matplotlib 
Python :: how to get int input in python 
Python :: Return the number of times that the string "hi" appears anywhere in the given string. python 
Python :: is string mutable in python 
Python :: json decode py 
Python :: selenium save webpage as pdf python 
Python :: how to check if an element is in a list python 
Python :: Convert two lists into a dictionary in python 
Python :: pyqt5 image center 
Python :: msg.author discord.py 
Python :: python string remove accent 
Python :: find the highest id in model django 
Python :: get count of values in column pandas 
Python :: print first word of a string python and return it 
Python :: how to for loop for amount in list python 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =