初学面向对象
作者:互联网
# 定义Student类
class Student:
def __init__(self,name,xuehao,phone): # 初始化函数
self.name = name
self.xuehao = xuehao
self.phone = phone
self.__password = '123'
def say_hello(self):
print("你好,我是{n},密码是{p}".format(n=self.name,p=self.__password))
self.print_phone()
def print_phone(self):
print("你好,我是{n},我的电话是{m}".format(n=self.name,m=self.phone))
# 实例化
zhangsan = Student("zhangsan","01","123456")
# 属性
zhangsan.xuehao
'01'
# 调用方法
zhangsan.say_hello()
你好,我是zhangsan,密码是123
你好,我是zhangsan,我的电话是123456
zhangsan.print_phone()
你好,我是zhangsan,我的电话是123456
标签:name,phone,self,xuehao,面向对象,初学,print,zhangsan 来源: https://blog.csdn.net/HYX_joker/article/details/110526210