instance scope in python code example
Example 1: instance variable in python
class Car: wheels = 4
Example 2: instance method in python
class Student:
def __init__(self, a, b):
self.a = a
self.b = b
def avg(self):
return (self.a + self.b) / 2
s1 = Student(10, 20)
print( s1.avg() )
Example 3: class variable in python
class some_variable_holder(object):
var = "This variable is created inside the class some_variable_holder()."
def somefunc(self):
print("Random function ran.")
thing = some_variable_holder()
another_thing = some_variable_holder()
thing.var
another_thing.var