搜尋此網誌

2026年3月9日星期一

Classes and Objects in Python

In Python, there is no difference between using double quotes ("Samson") and single quotes ('Samson') when defining a string. Both represent the same type of string object.

print("Samson")  # Output: Samson

print('Samson')  # Output: Samson

In Python, __init__ is a special method used in classes. It’s often called the constructor, because it runs automatically whenever you create a new object (an instance) from that class.

In Python, class names are typically written with a capitalized first letter.

Class: A blueprint or template. It defines what attributes (data) and methods (behavior) its objects will have.

Object: A specific instance created from that class. Each object has its own data but follows the structure defined by the class.

Microsoft Copilot

沒有留言:

發佈留言