PythonStudy——赋值运算符 Assignment operator

eg:
num = 10
num += 1 # 等价于 num = num + 1 => 11
print(num)
特殊操作:
1.链式赋值
a = b = num
print(a, b, num, id(a), id(b), id(num))
2.交叉赋值
# 传统交换赋值
x = 10
y = 20
temp = xx = yy = tempprint(x, y) Output:
20 10
x, y = y, x
print(x, y)
3.解压赋值
ls = [3, 1, 2] a, b, c = ls
print(a, b, c) res = ls
print(res) Output:
3 1 2
[3, 1, 2]
# _是合法的变量名,会接受值,但我们认为_代表该解压位不用接收,用_来接收表示
_, _, g = ls
print(g)
Output:
2
PythonStudy——赋值运算符 Assignment operator的更多相关文章
- Lintcode208 Assignment Operator Overloading (C++ Only) solution 题解
[题目描述] Implement an assignment operator overloading method. Make sure that: The new data can be copi ...
- Effective C++ 第0章 copy constructor和copy assignment operator
拷贝构造函数(copy constructor)被用来以一个对象来初始化同类型的另一个对象,拷贝赋值运算符(copy assignment operator)被用来将一个对象中的值拷贝到同类型的另一个 ...
- copy constructor和copy assignment operator的区别
拷贝构造函数(copy constructor)被用来以一个对象来初始化同类型的另一个对象,拷贝赋值运算符(copy assignment operator)被用来将一个对象中的值拷贝到同类型的另一个 ...
- Java基础-赋值运算符Assignment Operators与条件运算符Condition Operators
Java基础-赋值运算符Assignment Operators与条件运算符Condition Operators 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.赋值运算符 表 ...
- Default Assignment Operator and References
We have discussed assignment operator overloading for dynamically allocated resources here . This is ...
- When should we write our own assignment operator in C++?
The answer is same as Copy Constructor. If a class doesn't contain pointers, then there is no need t ...
- Copy constructor vs assignment operator in C++
Difficulty Level: Rookie Consider the following C++ program. 1 #include<iostream> 2 #include&l ...
- How to use base class's assignment operator in C++
看了android下的代码,好长时间没看了,有个关于C++的知识点不是很清楚,查了下: 如何使用基类中的赋值运算符? 引述自http://stackoverflow.com/questions/122 ...
- PythonStudy——运算符优先级 Operator precedence
运算符优先级 以下所列优先级顺序按照从低到高优先级的顺序:同行为相同优先级. 1 Lambda #运算优先级最低 2 逻辑运算符: or 3 逻辑运算符: and 4 逻辑运算符:not 5 成员测试 ...
随机推荐
- P1908 逆序对
传送门 这题似乎不应该出现在这里.. 日常做法(归并): #include<iostream> #include<cstdio> #include<algorithm&g ...
- 1.6 安全认证与授权(springboot与安全)
引言:以下文档是学习尚硅谷关于springboot教学视频后整理而来! 一.安全 认证(Authentication):证明你是谁? 授权(Authorization):你能干什么? 参考资料: Sp ...
- Listview自定义了子View导致listview的onitemclick事件无效
原因是子View的点击事件抢占了listview的点击事件 解决办法: 1. 子View根布局 设置 android:descendantFocusability="blocksDescen ...
- Java原生API访问MongoDB
1.pom.xml <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java ...
- git项目远程地址修改后本地如何处理
今天运维人员为了方便管理,将远程的项目地址给迁移了, 原来是 git@git.lalala.com:yuanlaide/happy.git 变成了 git@git.lalala.com:houlaid ...
- 『PyTorch』第五弹_深入理解Tensor对象_下:从内存看Tensor
Tensor存储结构如下, 如图所示,实际上很可能多个信息区对应于同一个存储区,也就是上一节我们说到的,初始化或者普通索引时经常会有这种情况. 一.几种共享内存的情况 view a = t.arang ...
- 【JS】【6】判断一个元素是否在数组中
摘要: 有三种方式: 1,jquery的inArray方法 2,数组的indexOf方法 3,普通的for循环方法 正文: 1,jquery的inArray方法 /** * @param {Objec ...
- PI接口开发之调java WS接口
java提供的WSDL:http://XXX.XXX.XXX.XX/XXXXXXXcrm/ws/financialStatementsService?wsdl 登陆PI,下载Enterprise Se ...
- 【C/C++】小坑们
1.printf("%03d", a); // 输出 a,占 3 位,不够则左边用 0 填充 2.memcpy 所在头文件为 <string.h> 3.string s ...
- 记不住的Android活动的生命周期
Activity基类定义了管理一个互动的生命周期的一系列事件. Activity生命周期的一系列事件onCreate()——当前活动首次被创建时使用.onStart()——当前活动对用户可见时调用.o ...