zoukankan      html  css  js  c++  java
  • python 面向对象的类

    参考《learn python hard way》

      网址:https://learnpythonthehardway.org/book/ex41.html

    class X(Y)
    "Make a class named X that is-a Y."
    创建一个叫x的类,类x是y(类x 继承y),例如‘三文鱼‘是‘鱼’
    class X(object): def __init__(self, J)
    "class X has-a __init__ that takes self and J parameters."
    类中有一个叫__init__,在__init__中有两个参数self 和J
      一般都会有__init__就是初始化,在没有类的函数中是从第一个非def的语句开始运行
      在如果有需要运行或是初始化的内容,可以加在__init__中
    class X(object): def M(self, J)
    "class X has-a function named M that takes self and J parameters."
    类中定义了一个叫M的函数,M中有self和J的参数,self这个参数在类中的各个函数都必须有。
    foo = X()
    "Set foo to an instance of class X."
    用foo来实例化类X
    foo.M(J)
    "From foo get the M function, and call it with parameters self, J."
    从foo中获得函数M,然后调用函数M,函数M中的参数是J。
      这里的foo一定是实例化类后的
    foo.K = Q
    "From foo get the K attribute and set it to Q."
    从foo中获得属性K,然后把它给K
      相当于self.chose = true或者M.color = 'blue'
  • 相关阅读:
    Android-View动画
    Android-RemoteView-桌面小部件
    系统的Drawable(四)-LayerListDrawable
    Android-Drawable(三)
    系统的Drawable(二)-Selector
    系统的Drawable(一)
    Android View事件分发-从源码分析
    打游戏要存进度-备忘录模式
    Java 内部类.md
    docker 常用 命令
  • 原文地址:https://www.cnblogs.com/zhuzhu2016/p/6180763.html
Copyright © 2011-2022 走看看