- python是面向对象语言,一切皆对象,既支持面向对象编程,也支持函数式编程
第一个功能:print传入的值
①
def func(a):
print(a)
def main():
func('zhangsan')
②
class Demo:
def __init__(self):
self.a = None
def func(self):
print(self.a)
def main():
d = Demo()
d.a = 'zhangsan'
d.func()
③
class Demo:
def __init__(self):
self._a = None
@property
def a(self):
return self._a
@a.setter
def a(self, value):
self._a = value
def func(slef):
print(self.a)
def main():
d = Demo()
d.a = 'zhangsan'
d.func()