# -*- coding: utf-8 -*-
#创建一个学生类,基本属性id、姓名、年龄
class Student(object):
def __init__(self,stuId,stuName,stuAge):
self.stuId = stuId
self.stuName = stuName
self.stuAge = stuAge
#getter
def getStuName(self):
return self.stuName
#setter
def setStuName(self,stuName):
self.stuName = stuName
#类似C#简单封装
stuProprety = property(getStuName,setStuName)
#查找dy同学是否存在
def find(stuName):
if "dy" == stu.stuProprety:
print "find dy"
else:
print "no such student"
if __name__ == '__main__':
stu = Student(1,"dy",20)
find(stu.stuProprety)
print stu.stuProprety
stu.stuProprety = "YD"
find(stu.stuProprety)
print stu.stuProprety
property 类似C#的简单封装,级直接可以通过对象对属性进行获取、赋值
Python模块学习--property
最新推荐文章于 2022-12-11 23:12:10 发布