Objects are mutable
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
Objects are mutable的更多相关文章
- Think Python - Chapter 15 - Classes and objects
15.1 User-defined typesWe have used many of Python’s built-in types; now we are going to define a ne ...
- JavaScript Objects in Detail
JavaScript’s core—most often used and most fundamental—data type is the Object data type. JavaScript ...
- Processing Images
https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_ ...
- JavaScript Patterns 3.1 Object Literal
Basic concept Values can be properties: primitives or other objects methods: functions User-defined ...
- C# - String与StringBuilder
A String object is called immutable (read-only), because its value cannot be modified after it has b ...
- 《Think Python》第15章学习笔记
目录 <Think Python>第15章学习笔记 15.1 程序员定义的类型(Programmer-defined types) 15.2 属性(Attributes) 15.3 矩形( ...
- JS对象深入剖析
对象概述 Objects are mutable keyed collections. An object is a container of properties, where a propert ...
- python sentence
1.while for 增加了循环正常结束后执行的else代码块. 2.Objects are mutable 3.import copy p1 = Point() p2=copy.copy(p1) ...
- Why are C# structs immutable?
Compiler Error CS1612 Cannot modify the return value of 'expression' because it is not a variable cl ...
随机推荐
- 百度分页效果之纯jsp版
数据库连接工具类 package com.gao.page.utils; import java.sql.Connection; import java.sql.DriverManager; publ ...
- shareSDK的初步使用(shareSDK中微信、qq等兼容问题,以及cocoapods支持架构冲突问题的解决)
第一次使用shareSDK来做第三方分享,可是.昨天一天都是在调试bug,一直错误不断! 先说下我的开发环境: xcode:5.1 真机调试:iPhone5s 我们都知道xcode5.1以后開始是支持 ...
- AutoCompleteTextView和Spinner的使用方法
首先说明AutoCompleteTextView的使用方法.主要是起到自己主动填充的作用.输入keyword,假设存在该字便能够自己主动填充.代码例如以下 activity_main.xml < ...
- App 签名过期或泄露怎么办?别担心,Google 已经给出解决方案!
一.序 在将 App 发布到市场之前,很重要的一个步骤就是为 APK 进行签名,大部分时候,这个操作隐藏在了打包的流程中,而不被我们注意到. 签名的作用,除了证明 App 的所有权之外,还可以帮助 A ...
- android drawable资源调用使用心得
1. 调用顺序 android 调用应用图片资源时,会优先选择当前手机屏幕dpi对应的的文件夹(如drawable-ldpi, drawable-mdpi, drawable-hdpi, drawab ...
- 用exp命令按用户导出的DMP文件缺少表,某些表是空表
1.用以下这句查找空表并生成执行命令 select 'alter table '||table_name||' allocate extent;' from user_tables where num ...
- TYVJ1415 差分约束
思路: i–>i+1连一条边权为0的边 i–>i-1连一条边权为-1的边 start-1 ->end 连一条边权为w的边 求0->n的最长路即可 //By SiriusRen ...
- javascript对象的相关操作
Window对象 我们知道浏览器对象模型(BOM)是javascript的组成之一,它提供了独立于内容与浏览器窗口进行交互的对象.其分层结构如下: window对象是整个BOM的核心其有documen ...
- App.config:配置系统未能初始化的异常
如上图所示:App.config文件是这样配置的,在后台代码”ISchedulerFactory scheduler = new StdSchedulerFactory();“中抛出了异常 经网上查资 ...
- Android tablayout增加选择tab 的事件.
tablayout在点击或者滑动的时候会触发监听事件 , 当你调用这个方法的时候 会触发事件 mTablayout.addOnTabSelectedListener(new TabLayout.On ...