zoukankan      html  css  js  c++  java
  • 08.Python基础--面向对象深入

    self 调用类的属性:

    写个类来看看:

    class human(object):

      speak = 'ma name is hello'

      emotion = 'I love you'

      def func1(self):

        self.speak = s

        self.emotion = e

        return s,e

    Bob = human()

    print(Bob.func1())

    __init__初始化用法:

    class black_human(human):

      def __init__(self,color):

        c = self.color

        return c

    zhangfei = black_human('black')    #black_human是human的子类(继承关系),故zhangfei继承了human类,将'black'作为参数传给__init__里面的color

    实际使用:

    class Zhou(object):
        def __init__(self,a,b,c,d):
            self.a = a
            self.b = b
            self.c = c
            self.d = d
        def func1(self):
            a = self.a
            b = self.b
            a = a +'aaaaaa'
            b = b + 'bbbbbbb'
            return a,b
    
        def func2(self):
            c = self.c
            d = self.d
            data1,data2 = self.func1()
            print(data1+data2+c+d)
    
    if __name__ =='__main__':
        # 假设我们需要用到的参数 a,b,c,d...  这里也可以用到参数解析器模块(后续)
        a = 'one'
        b = 'two'
        c = 'three'
        d = 'four'
        ok = Zhou(a,b,c,d)
        ok.func2()

      

  • 相关阅读:
    SpringMVC学习笔记----常用注解
    python常用模块学习1
    python基础模块,包
    python-验证功能的装饰器示例
    python闭包及装饰器
    关于windows服务器配置
    python高阶函数
    python-生成器和迭代器
    linux--基础知识5
    python基础-文件操作的其他方法
  • 原文地址:https://www.cnblogs.com/zhouA/p/14500365.html
Copyright © 2011-2022 走看看