class variable and instance variable in python code example
Example 1: instance variable in python
class Car: wheels = 4 # <- Class variable def __init__(self, name): self.name = name # <- Instance variable
Example 2: 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)