1.创建类的关键字:class

2.构造函数__init__(),自动初始化属性值

class Cup:

    #构造函数,初始化属性值
def __init__(self,capacity,color):
self.capacity=capacity
self.color=color def retain_water(self):
print("杯子颜色:"+self.color+",杯子容量:"+self.capacity+",正在装水.") def keep_warm(self):
print("杯子颜色:"+self.color+",杯子容量:"+self.capacity+",正在保温.") cup1=Cup('450ml','红色')
cup2=Cup('700ml','黄色')
cup1.retain_water()
cup2.keep_warm()

最新文章

  1. 前端UI框架和JS类库
  2. Reflector 已经out了,试试ILSpy[转]
  3. win 7 普通家庭版 装IIS
  4. V-rep学习笔记:机器人逆运动学数值解法(Cyclic Coordinate Descent Method)
  5. C++库大全(转)
  6. WebService简单使用
  7. 库函数 Math
  8. 图片拉伸: stretchableImageWithLeftCapWidth
  9. Tsinsen-A1490 osu! 【数学期望】
  10. treeview树(利用数据表实现)带展开
  11. PYTHON实现算术表达式构造二叉树
  12. for循环输出菱形的形状【java】
  13. 项目Alpha冲刺4
  14. navicat 连接postgresql报错pg_hba.conf
  15. URLconf
  16. 安装配置Windows Live Writer做为博客客户端
  17. Django 请求参数
  18. hive使用derby的服务模式(可以远程模式)
  19. 【算法学习】【洛谷】树链剖分 & P3384 【模板】树链剖分 P2146 软件包管理器
  20. tortoisegit 7步 学会git分支

热门文章

  1. Spring cloud微服务安全实战-7-7自定义metrics监控指标(2)
  2. Python 初级 6 循环 (三)
  3. 【翻译】Flink Table Api & SQL — Catalog Beta 版
  4. 【翻译】Flink Table Api & SQL — Hive Beta
  5. [转]git登录账号密码错误remote: Incorrect username or password
  6. [LeetCode] 203. Remove Linked List Elements 移除链表元素
  7. Netty实现SSL双向验证完整实例
  8. 使用office365 world2016发布编辑备份你的博客
  9. mysql 5.7 sql_mode设置 坑
  10. centos7 intall nvidia driver