attributes of an object in python code example
Example 1: python object with attributes
class Object(object):
pass
a = Object()
a.somefield = somevalue
Example 2: attributes in python
class Monkey(object):
def __init__(self, name): # This will done automatically when cmd in 7th line will be executed
self.name = name # This is an attribute.
def speak(self): # This is a method
print("Hello! I am " + self.name)
IronMan = Monkey('TonyStark')
IronMan.speak() # This will use the function 'speak' defind in class 'Monkey'
# Created By ....