We can change the state of an object by making an assignment to one of its attributes. For example, to change the size of a rectangle without changing its position, you can modify the values of width and height:

box.width = box.width + 50
box.height = box.height + 100

You can also write functions that modify objects. For example, grow_rectangle takes a Rectangle object and two numbers, dwidth and dheight, and adds the numbers to the width and height of the rectangle:

def grow_rectangle(rect,dwidth,dheight):
rect.width += dwidth
rect.height += dheight

Here is an example that demonstrates the effect:

Inside the function, rect is an alias for box, so if the function modifies rect, box changes.

from Thinking in Python

最新文章

  1. c# 生成SHA1加密字符串
  2. 【BZOJ-3757】苹果树 块状树 + 树上莫队
  3. MySQL主从分离读写复制
  4. OpenGL 和OpenGL ES简介
  5. shelll函数求两个输入数字之和
  6. ajax检测账户是否存在
  7. 解决:The Operation couldn't be completed.(LaunchServicesError error 0.)
  8. 利用ZABBIX的RPC-JSON作API扩展应用示例
  9. 201521123039 《java程序设计》第一周学习总结
  10. maven 控制台 打包
  11. .NET EF框架的安装、及三种开发模式
  12. UBNT ex-r +netgear gs105e v2 +ap 设置vlan 步骤记录 及相关知识整理
  13. Python 设计模式之路
  14. 在线xss练习平台
  15. Windows PowerShell 入門(6)-関数編1
  16. useful tips for python
  17. php : 开发记录(2017-03-10)
  18. 第二个spring, 第7天
  19. Spring+Struts+Mybatis+Shiro整合配置
  20. EF语句拦截器-匹配当前的Controller,Action,User

热门文章

  1. 各种List、Map、Set的比較
  2. POJ 2318 叉积判断点与直线位置
  3. Codeforces 659F Polycarp and Hay 并查集
  4. sql 查询所有数据库-表-表结构
  5. IEEE Access的模板的问题
  6. Android ViewPager系列之ViewPager一屏显示多个子页面
  7. Intellij IDEA 2018.3激活破解方法(解决key is invalid)
  8. 关于Python的装饰器
  9. (2016北京集训十三)【xsy1532】网络战争 - 最小割树+树上倍增+KD树
  10. 写入~/.bashrc 文件