Python short course: Class basics in Python

 Class is crucial for OOP. It can generate many instances of the class object. Think about the Monkey King generating many fake Monkey Kings by pulling his fur in the Journey to the West. Below are a basic class object:


In [2]: class ClassTest:
   ...:     def setdata(self, value):
   ...: = value
   ...:     def display(self):
   ...:         print(

In [3]: class_test = ClassTest()

In [4]: class_test.setdata("I love Python")

In [5]: class_test.display()
I love Python

In [6]: class_test_2 = ClassTest()

In [7]: class_test_2.setdata(12345)

In [8]: class_test_2.display()

Lutz, Mark Learning Python (5th ed.) 2013 O'Reilly: CA p. 1594


Popular posts from this blog

Lab's weekly topic - week 50 2023 - Detailed explanation for encoder of U-Net

Lab's weekly topic - week 49, 2023 - What's limitations and possible solutions for a new AI tools to detect blood poisoning?

Lab's recommendation: Awesome books to learn machine learning and AI (continue updating)