IIPP Week 6
来源:互联网 发布:大数据 项目 编辑:程序博客网 时间:2024/04/28 02:10
Week 6a - Classes
Object-oriented Programming - 1
Capitalize the Class Name
Create a Class
class_obj = ClassName(...)
Parameter self
self
as a parameter of the method of class, which on behalf of class itself
double underbar
- These method get called behind your back by Python
- special function
__init__
__str__
(print Class
can automatically call this method, also we can call it byprint str(Class)
)
- don’t use it for normal function
Object-oriented Programming - 2
suitable for other situation
1 Class ball -> different Class Domain (RectangularDomain or CircleDomain)
Working with Objects
We can write a function draw()
in Class, don’t forget to pass parameter canvas
to this function
Week 6b - Tiled Image
Programming Tips - 6
Object Returned by __init__
__init__
will return self automatically
Object of Class Share Data like List
################### Object shared state# Mutation of shared stateclass Point2: def __init__(self, coordinates): self.coords = coordinates def set_coord(self, index, value): self.coords[index] = value def get_coord(self, index): return self.coords[index]coordinates = [4, 5]p = Point2(coordinates)q = Point2(coordinates)r = Point2([4, 5])p.set_coord(0, 10)print p.get_coord(0)print q.get_coord(0)print r.get_coord(0)################### Objects not sharing stateclass Point3: def __init__(self, coordinates): self.coords = list(coordinates) def set_coord(self, index, value): self.coords[index] = value def get_coord(self, index): return self.coords[index]coordinates = [4, 5]p = Point3(coordinates)q = Point3(coordinates)r = Point3([4, 5])p.set_coord(0, 10)print p.get_coord(0)print q.get_coord(0)print r.get_coord(0)
阅读全文
0 0
- IIPP Week 6
- IIPP Week 2
- IIPP Week 3
- IIPP Week 4
- IIPP Week 5
- IIPP Week 8
- week 6
- week after week----6月的生活
- Week 6 - Mon.
- Week 6 - Wed.
- Week 6 - Fri. Graduated
- Week 6, SOC
- week-6作业
- week report 2015.12.6
- 1090. Highways(week 6)
- LeetCode Week 6: IPO
- week
- Week
- 最大连续子序列(动态规划)
- 微信小程序--发送短信倒计时
- 【c语言】判断一个文件里的括号是不是匹配
- Vue全局方法注册
- #乘积的末3位
- IIPP Week 6
- Keil 5-ARM: No Algorithm found for: 08000000H
- Hashtable
- 利用EXPLAIN分析sql语句的性能
- 办公界黑科技—pdf转jpg格式转换器
- NPM常用命令
- 函数节流(throttle)与函数去抖(debounce)
- Hyperledger Composer 常用术语
- 关于java中用jxl从ex表格读取数据转存到数据库里