Python第八课

一、Python中的面向对象编程

everything in python is an object and has a type.

  • can create new objects of some type
  • can manipulate objects
  • can destroy objects
    • explicitly using del or just "forget" about them
    • python system will reclaim destroyed or inaccessible objects - called "garbage collection"

面向对象编程有很多优势此处不再细说。在Python中使用class关键字定义新类,标准定义如下所示:

# Python

class Coordinate (object):
    # define attributes here

圆括号中的object代表Coordinate是Python中的一个对象,并且继承object的所有attributes(即所有的data和procedures)。

  • Coordinate is a subclass of object
  • object is a superclass of Coordinate

首先,如何定义初始化一个类的方法(method)呢?这时候得使用一个特殊的方法叫做__init__,代码如下所示:

# Python

class Coordinate(object):
    """ A coordinate made up of an x and y value """
    def _
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
python基础教程至60课(基础) 【Python 第1课】安装 6 【Python 第2课】print 7 【Python 第3课】IDE 10 【Python 第4课】输入 12 【Python 第5课】变量 14 【Python 第6课】bool 16 【Python 第7课】if 19 【Python 第8课】while 23 【Python 第9课】random 26 【Python 第10课】变量2 28 【Python 第11课】逻辑判断 29 【Python 第12课】 for循环 30 【Python 第13课】字符串 32 【Python 第14课】字符串格式化 34 【Python 第15课】循环的嵌套 35 【Python 第16课】字符串格式化2 37 【Python 第17课】类型转换 38 【Python 第18课】 bool类型转换 40 【Python 第19课】 函数 41 【Python 第21课】 函数的参数 46 【Python 第22课】 函数应用示例 47 【Python 第23课】 if, elif, else 49 【Python 第24课】 if的嵌套 54 【Python 第25课】 初探list 56 【Python 第26课】 操作list 58 【Python 第28课】 字符串的分割 65 【Python第29课】连接list 71 【Python 第30课】字符串的索引和切片 72 【Python 第31课】读文件 74 【Python 第32课】写文件 76 【Python 第33课】处理文件中的数据 77 【Python 第34课】 break 83 【Python 第35课】 continue 84 【Python 第36课】异常处理 87 【Python 第37课】字典 90 【Python 第38课】模块 93 【Python 第39课】用文件保存游戏(1) 96 【Python 第40课】用文件保存游戏(2) 98 【Python 第41课】用文件保存游戏(3) 101 【Python 第42课】函数的默认参数 105 【Python 第43课】查天气(1) 107 【Python 第44课】查天气(2) 108 【Python 第45课】查天气(3) 111 【Python 第46课】查天气(4) 113 【Python 第47课】面向对象(1) 116 【Python 第48课】面向对象(2) 117 【Python 第49课】面向对象(3) 118 【Python 第50课】面向对象(4) 120 【Python 第51课】 and-or技巧 123 【Python 第52课】元组 124 【Python 第53课】数学运算 125 【Python 第54课】真值表 127 【Python 第55课】正则表达式(1) 128 【Python 第56课】正则表达式(2) 130 【Python 第57课】正则表达式(3) 131 【Python 第58课】正则表达式(4) 134 【Python 第59课】正则表达式(5) 135 【Python 第60课】随机数 137

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你可真搞笑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值