Python Class Example: Creating a Person Class with Attributes and Methods
The above code defines a class called 'Person' which has two attributes, 'name' and 'age', and a method called 'say_hello' which prints out a greeting message with the person's name and age.
In the 'if name=='main': ' block, an instance of the class 'Person' is created with the name 'wangmei' and age '19'. Then the 'say_hello' method of this instance is called, which prints out the greeting message 'Hello, my name is wangmei and I am 19 years old.'
原文地址: https://www.cveoy.top/t/topic/nZKL 著作权归作者所有。请勿转载和采集!