// 8 day(2016/8/11)

38. In python , it is oop.

class Baskball:
         def setName(self, name):
                self.name = name
         def kick(self):
                print('my name is %s' % self.name)
      baskball = Baskball()
      baskball.setName('baskball')
      baskball.kick()

-> my name is baskball

class Ball:
         def __init__(self, name):
              self.name = name
         def kick(self):
              print('my name is %s' % self.name)
       b = Ball('tom')
       b.kick()

-> my name is tom

39. In python ,how to define private variable,

such as:

class Person:
          name = 'roy'
     p = Person()
     print(p.name)

-> roy

if you use:

class Person:
          __name = 'roy'
     p = Person()
     print(p.__name) || print(p.name)

-> error

if you use __ before variable ,you can access it direct.

class Person:
           __name = 'roy'
           def getName(self):
                return self.__name
     p = Person()
     print(p.getName())

-> roy

class Person:
       __name = 'roy'
    p  = Person()
    print(p._Person__name)

-> roy

40. inheritance mechanism

class SubClassName:(ParentClassName):

……

class Parent:
          def hello(self):
                print('write code change world')

class Child(Parent):
          pass

p = Parent()
     p.hello()

c = Child()
     c.hello()

->

write code change world

write code change world

if subclass methon is same with parent , it will cover parent method, such as:

class Child(Parent):

def hello(self):

print('believe youself')

c = Child()

c.hello()

-> believe youself

now we will study a simple example:

import random as r
     class Fish:
          def __init__(self):
              self.x = r.randint(0,10)
              self.y = r.randint(0,10)
          def move(self):
             self.x -= 1
             print('my position is:',self.x, self.y)

class Shark(Fish):
         def __init__(self):
            #Fish.__init__(self)
            super().__init__()
            self.hungry = True

def eat(self):
             if self.hungry:
                print('eat eat eat')
                self.hungry = False
            else:
                print('not hungry')

1,Fish.__init__(self)
       2,super().__init__()

1 and 2 is same ,if you not add this ,you invoke move in Shark ,it will error, because ,__init__ will cover parent method, you call move() ,it will not found x and y. if you use  1 and 2, it will solve this question

multiply parent class:

class subClassName:(parent1ClassName, parent2ClassName):

……

class Base1:
         def fool1(self):
               print('it is fool1')

class Base2:
        def fool2(self):
              print('it is fool2')

class c(Base1, Base2):
           pass

c = c()
     c.fool1()
     c.fool2()

-> it is fool1

-> it is fool2

Python Base Five的更多相关文章

  1. Python Base of Scientific Stack(Python基础之科学栈)

    Python Base of Scientific Stack(Python基础之科学栈) 1. Python的科学栈(Scientific Stack) NumPy NumPy提供度多维数组对象,以 ...

  2. Python Base Four

    35. In python, file operation syntax is similar to c. open(file,'r',……) //the first parameters is ne ...

  3. Python Base One

    //this is my first day to study python, in order to review, every day i will make notes (2016/7/31) ...

  4. Python Base Three

    //sixth day to study python(2016/8/7) 32. In python , there are have an special type dictionary , it ...

  5. Python Base Two

    //fourth day to study python 24. In python , how to create funcation. we can use def to define funca ...

  6. 2019-04-18 Python Base 1

    C:\Users\Jeffery1u>python Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64 ...

  7. python base 64

    python中base64编码与解码   引言: 在一些项目中,接口的报文是通过base64加密传输的,所以在进行接口自动化时,需要对所传的参数进行base64编码,对拿到的响应报文进行解码: Bas ...

  8. Python Base HTTP Server

    import BaseHTTPServer import cgi, random, sys MESSAGES = [ "That's as maybe, it's still a frog. ...

  9. 基于Python+协程+多进程的通用弱密码扫描器

    听说不想扯淡的程序猿,不是一只好猿.所以今天来扯扯淡,不贴代码,只讲设计思想. 0x00 起 - 初始设计 我们的目标是设计一枚通用的弱密码扫描器,基本功能是针对不同类型的弱密码,可方便的扩展,比如添 ...

随机推荐

  1. 【转】HTTP Live Streaming直播(iOS直播)技术分析与实现

    HTTP Live Streaming直播(iOS直播)技术分析与实现 不经意间发现,大半年没写博客了,自觉汗颜.实则2012后半年,家中的事一样接着一样发生,实在是没有时间.快过年了,总算忙里偷闲, ...

  2. 学习JavaScript你必须掌握的8大知识点!

    大知识点! 一.JavaScript思维导图之<变量>的学习 二.    JavaScript思维导图之<函数基础>  三.JavaScript思维导图之<基本dom操作 ...

  3. Java多线程 编写三各类Ticket、SaleWindow、TicketSaleCenter分别代表票信息、售票窗口、售票中心。 售票中心分配一定数量的票,由若干个售票窗口进行出售,利用你所学的线程知识来模拟此售票过程。

    package com.swift; import java.util.ArrayList; import java.util.HashMap; import java.util.List; impo ...

  4. Java第11次作业:什么是继承?继承的好处?什么是覆写?super()?构造代码块?子父类初始化顺序? 抽象类能用final声明吗?final关键字声明类 方法 变量以及全局常量?抽象类的构造方法?

    什么是继承? 继承是以父类为基础,子类可以增加新的数据或新的功能.子类不能选择性地继承父类.这种技术使得复用以前的代码非常容易. JAVA不支持多继承,单继承使JAVA的继承关系很简单,一个类只能有一 ...

  5. iOS 证书、真机调试、发布 App Store

    之前对iOS的证书弄的很不清楚,Xcode里面也有各种证书,作为一只有强迫症的巨蟹座,这是不能忍的 趁着准备发布自己的第一个app,梳理一下这块内容 主要参考了这几篇文章: iOS开发:创建真机调试证 ...

  6. sql 经典加强巩固练习题

    由于本人需要加强巩固一下数据库知识,就搜罗了一些题目来练习,感觉不错,故分享一下资源难度层度依次上升这50道里面自认为应该没有太多错误,而且尽可能使用了最简单或是最直接的查询,有多种不相上下解法的题目 ...

  7. 14Shell脚本—判断语句

    判断语句 Shell脚本中的条件测试语法可以判断表达式是否成立,若条件成立则返回数字0,否则便返回其他随机数值. 条件测试语法的执行格式为 [ 条件表达式 ],切记,条件表达式两边均应有一个空格. 条 ...

  8. tempfs详解

    致因 在平常工作中,我们经常需要查看Linux服务器磁盘挂载使用情况,可以使用df命令,不知大家注意到没有,我们使用此命令除了会查看到系统盘以及数据盘挂载情况,还会看到一个tmpfs也在挂载. [ro ...

  9. Linux 用户管理(二)

    一.groupadd --create a new group 创建新用户 -g  --gid GID 二.groupdel --delete a group 三.passwd --update us ...

  10. Python爬虫,爬取实验楼全部课程

    目的: 使用requests库以及xpath解析进行实验楼所有课程,存入MySQL数据 库中. 准备工作: 首先安装,requests库,lxml库,以及peewee库.在命令行模式,使用以下命令. ...