美文网首页程序员
day 4(python notes)

day 4(python notes)

作者: 君宝儿 | 来源:发表于2016-05-16 20:35 被阅读64次

note 1:声明类 class 类名:对象定义对象p=类名()。
note 2:类属性,属性名前加""表明为私有属性,否则公有。
note 3:Python方法分为对象方法,类方法,静态方法。对象方法具有self参数。类方法使用修饰器@classmethod,具有cls参数。静态方法使用修饰器@staticmethod,不需要参数。

Paste_Image.png
note 4:对象方法分为公有方法和私有方法两种。若在方法名前加两个下划线“
”表示该方法是私有。对象方法与普通函数只有一个区别,必须有一个额外的第一参数名称(self),self等同于C++语言的this指针,指向对象本身,当对象调用该方法时,Python就将对象作为第一个参数传递给self。 Paste_Image.png

note 5:类方法属于类,类方法只能用类名调用,具有cls参数。

Paste_Image.png

note 6:静态方法。通过Python修饰器@staticmethod实现,静态方法只能通过类名调用,静态方法不能访问属于对象的成员,只能访问属于类的成员。

Paste_Image.png
note 7:对象生命周期从构造函数开始,析构函数结束。Python中构造函数定义语法格式为:def init(): Paste_Image.png
note 8:析构函数是del,用来释放对象占用的资源。 Paste_Image.png

相关文章

  • day 4(python notes)

    note 1:声明类 class 类名:对象定义对象p=类名()。note 2:类属性,属性名前加""表明为私有...

  • 笃学奖-Topic 2-A15161-甘比精读

    Notes for Levelling the paying field Day4: 单次作业 Vocabular...

  • [Python]BeautifulSoup 4 notes

    BS4 BeautifulSoup是用来从HTML or XML中提取数据的Python lib。Beautifu...

  • day 6(python notes)

    note 1:python操作数据库,分别是数据库连接对象,游标。打开数据库时返回conn对象,是数据库连接对象c...

  • day 3(python notes)

    note 1:python中函数声明 def 函数名(形参列表): 。函数没有标明函数的开始结束花括号。函数名下的...

  • day 2(python notes)

    介绍Python的几种序列,字符串,列表,元组 note 1:list=[1,1.3,"a"] list[1:2]...

  • day 5(python notes)

    note1:继承通过派生类和基类实现。基类称为父类,派生类称为子类。继承语法如下:class SubClassNa...

  • Day04 - Python基础4

    Day04的课程要点记录详细教程地址:Day4 - Python基础4 | python装饰器 一、装饰器 1.1...

  • Python 笔记

    【2017.04.20】 List Comprehension Notes of Python Tutorial:...

  • Functional Python Programming -

    Learning notes on Functional Python Programming Book: Fun...

网友评论

    本文标题:day 4(python notes)

    本文链接:https://www.haomeiwen.com/subject/fwdmrttx.html