【Rollo的Python之路】面向对象 学习笔记 (一)

1.0.1 类的定义:

class Bra:
    
    def foo(self,name,age,gender,content):
        print(name,age,gender,content)
        

obj = Bar()
obj.foo()

函数定义:def +函数名(参数)

面向对象:

  class >>>>>类,class Bar: >>>>>>名字叫Bar的类

  def >>>>>>方法,def foo():>>>>>>名字叫foo 的方法

  self>>>>>> 方法里面的第一个参数必须是self.

1.0.2 执行:

函数:

  函数名(参数)

面向对象:

  obj = Bar() >>>>创建中间人,叫:对象或实例

  执行:obj.foo() 

猜你喜欢

转载自www.cnblogs.com/rollost/p/10923758.html