python-函数式编程&面向对象编程

  • 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()
posted @ 2021-09-11 18:25  花兒向陽開  阅读(83)  评论(0编辑  收藏  举报