Answers for "python property class"

1

class attributes in python

class MyClass:
  # Class attributes are defined outside of constructor
  class_attr = 0
  
  def __init__(self, inst):
    # Instance attributes are defined in the constructor
    self.instance_attr = inst
    
obj = MyClass(1)
print(obj.class_attr) # outputs 0
print(obj.instance_attr) # outputs 1
print(MyClass.class_attr) # outputs 0
print(MyClass.instance_attr) # raises AttributeError
Posted by: Guest on May-30-2021
-1

@property in python

Getting name
The name is: Adam
Setting name to John
Deleting name
Posted by: Guest on December-07-2020

Code answers related to "python property class"

Python Answers by Framework

Browse Popular Code Answers by Language