Basic knowledge of common operations of python-like objects
Basic creation and use of classes
class clas:
classVariables = '类变量'
cal1 = clas()
print(cal1.classVariables)
Advanced usage
class person:
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
def measureHeight(self, expectTheHeight):
actualHeight = expectTheHeight - 10
return actualHeight
def talent(self):
random1 = random.randint(0, 10)
if random1 > 3:
return "不配拥有天赋"
else:
talent1 = ["读书", "游戏", "经商", "混子"]
return talent1[random1]
person1 = person('李', 18, '男')
actualHeight = person1.measureHeight(190)
print(person1.name + '的实际身高为:' + str(actualHeight))
print(person1.name + '的天赋为:' +person1.talent())