how to declare a variable in python class code example
Example 1: what is a ython instance
An object belonging to a class. e.g. if you had an Employee class, each
individual employee would be an instance of the Employee class
Example 2: 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
Example 3: how to assign a variable to a class in python
class Shark:
animal_type = "fish"
location = "ocean"
followers = 5
new_shark = Shark()
print(new_shark.animal_type)
print(new_shark.location)
print(new_shark.followers)