Python_Class
2024-10-21 12:53:59
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()
最新文章
- 前端UI框架和JS类库
- Reflector 已经out了,试试ILSpy[转]
- win 7 普通家庭版 装IIS
- V-rep学习笔记:机器人逆运动学数值解法(Cyclic Coordinate Descent Method)
- C++库大全(转)
- WebService简单使用
- 库函数 Math
- 图片拉伸: stretchableImageWithLeftCapWidth
- Tsinsen-A1490 osu! 【数学期望】
- treeview树(利用数据表实现)带展开
- PYTHON实现算术表达式构造二叉树
- for循环输出菱形的形状【java】
- 项目Alpha冲刺4
- navicat 连接postgresql报错pg_hba.conf
- URLconf
- 安装配置Windows Live Writer做为博客客户端
- Django 请求参数
- hive使用derby的服务模式(可以远程模式)
- 【算法学习】【洛谷】树链剖分 &; P3384 【模板】树链剖分 P2146 软件包管理器
- tortoisegit 7步 学会git分支
热门文章
- Spring cloud微服务安全实战-7-7自定义metrics监控指标(2)
- Python 初级 6 循环 (三)
- 【翻译】Flink Table Api &; SQL — Catalog Beta 版
- 【翻译】Flink Table Api &; SQL — Hive Beta
- [转]git登录账号密码错误remote: Incorrect username or password
- [LeetCode] 203. Remove Linked List Elements 移除链表元素
- Netty实现SSL双向验证完整实例
- 使用office365 world2016发布编辑备份你的博客
- mysql 5.7 sql_mode设置 坑
- centos7 intall nvidia driver