Byte of Python-----Class

##Python##
##2018/4/10##
##面向对象编程##


##Point1 重要概念

#类与对象是面向对象编程的两个主要方面。一个类(Class)能够创建一种新的类型
#(Type),其中对象(Object)就是类的实例(Instance)。可以这样来类比:你可以拥有
#类型 int 的变量,也就是说存储整数的变量是 int 类的实例(对象)。

#对象可以使用属于它的普通变量来存储数据。这种从属于对象或类的变量叫作字段
#(Field)。对象还可以使用属于类的函数来实现某些功能,这种函数叫作类的方法
#(Method)。这两个术语很重要,它有助于我们区分函数与变量,哪些是独立的,哪些又是
#属于类或对象的。总之,字段与方法通称类的属性(Attribute)。

#字段有两种类型——它们属于某一类的各个实例或对象,或是从属于某一类本身。它们被分
#别称作实例变量(Instance Variables)与类变量(Class Variables)。

#通过 class 关键字可以创建一个类。这个类的字段与方法可以在缩进代码块中予以列出。


##Point2 Self

#类方法与普通函数只有一种特定的区别——前者必须有一个额外的名字,这个名字必须添加
#到参数列表的开头,但是你不用在你调用这个功能时为这个参数赋值,Python 会为它提供。
#这种特定的变量引用的是对象本身,按照惯例,它被赋予 self 这一名称。

#尽管你可以为这一参数赋予任何名称,但是强烈推荐你使用 self 这一名称——其它的任何
#一种名称绝对会引人皱眉。使用一个标准名称能带来诸多好处——任何一位你的程序的读者
#能够立
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
this is a book about python. it was written by Swaroop C H.its name is "a byte of python". Table of Contents Preface Who This Book Is For History Lesson Status of the book Official Website License Terms Using the interpreter prompt Choosing an Editor Using a Source File Output How It Works Executable Python programs Getting Help Summary 4. The Basics Literal Constants Numbers Strings Variables Identifier Naming Data Types Objects Output How It Works Logical and Physical Lines Indentation Summary 5. Operators and Expressions Introduction Operators Operator Precedence Order of Evaluation Associativity Expressions Using Expressions Summary 6. Control Flow Introduction The if statement ivUsing the if statement How It Works The while statement Using the while statement The for loop Using the for statement Using the break statement The continue statement Using the continue statement Summary 7. Functions Introduction Defining a Function Function Parameters Using Function Parameters Local Variables Using Local Variables Using the global statement Default Argument Values Using Default Argument Values Keyword Arguments Using Keyword Arguments The return statement Using the literal statement DocStrings Using DocStrings Summary 8. Modules Introduction Using the sys module Byte-compiled .pyc files The from..import statement A module's __name__ Using a module's __name__ Making your own Modules Creating your own Modules from..import The dir() function Using the dir function Summary 9. Data Structures Introduction List Quick introduction to Objects and Classes Using Lists Tuple Using Tuples Tuples and the print statement Dictionary Using Dictionaries Sequences Using Sequences References Objects and References More about Strings String Methods Summary 10. Problem Solving - Writing a Python Script The Problem The Solution First Version Second Version Third Version Fourth Version More Refinements The Software Development Process Summary 11. Object-Oriented Programming Introduction The self Classes Creating a Class object Methods Using Object Methds The __init__ method Using the __init__ method Class and Object Variables Using Class and Object Variables Inheritance Using Inheritance Summary 12. Input/Output Files Using file Pickle Pickling and Unpickling Summary 13. Exceptions Errors Try..Except Handling Exceptions Raising Exceptions How To Raise Exceptions Try..Finally Using Finally Summary 14. The Python Standard Library Introduction The sys module Command Line Arguments More sys The os module Summary 15. More Python Special Methods Single Statement Blocks List Comprehension Using List Comprehensions Receiving Tuples and Lists in Functions Lambda Forms Using Lambda Forms The exec and eval statements The assert statement The repr function Summary 16. What Next? Graphical Software Summary of GUI Tools Explore More Summary A. Free/Libré and Open Source Software (FLOSS) B. About Colophon About the Author C. Revision History Timestamp

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值