Access Class Properties through Instance Name
Can I access class properties through an instance name?
Yes, you can access class properties through an instance name, as long as there is no instance property that has the same name as a class property.
When you reference a property through the instance name in the following form:
Python will search for the given property name in instance_name.__dict__ first. If match found, return the value. If not match found, continue with the next step.
In the next step, Python will search the given property name in class_name.__dict__. If match found, return the value. If not match found, return error.
The following Python code shows you a good example of accessing class property through a instance name:
>>> class user(): ... nextID = 1 ... def __init__(self,name="Joe",age=25): ... self.id = user.nextID ... self.name = name ... self.age = age ... user.nextID = user.nextID + 1 ... >>> x = user() >>> x.nextID 2
2022-09-24, 1191🔥, 0💬
What Is session_register() in PHP? session_register() is old function that registers global variable...
Where to find tutorials on API Management Services at Azure Portal? Here is a list of tutorials to a...
What is Azure API Management Gateway? Azure API Management Gateway is the Azure Web server that serv...
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...