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 成员测试 ...
随机推荐
- 【HNOI 2018】游戏
Problem Description 一次小 \(G\) 和小 \(H\) 在玩寻宝游戏,有 \(n\) 个房间排成一列,编号为 \(1,2,-,n\),相邻房间之间都有 \(1\) 道门.其中一部 ...
- Qt5OpenGL.术语01
来自:QT 5.4+ OpenGL编程 - brain2004的专栏 - CSDN博客.html(https://blog.csdn.net/brain2004/article/details/707 ...
- leecode第一百六十九题(求众数)
class Solution { public: void quick_sort(vector<int>& nums,int res,int res_end) { )//错过,不能 ...
- MySQL5.5安装教程
登录MySQL:mysql -uroot -p密码 退出MySQL:exit | quit 查看数据库:show datab ...
- CentOs系统设置python版本
一.针对当前终端生效 最近云服务器安装了centos7系统,python默认版本是2.7.5,但是习惯用anaconda3, 安装anaconda3之后将系统默认python版本更改为python3. ...
- spring/java ---->记录和整理用过的注解以及spring装配bean方式
spring注解 @Scope:该注解全限定名称是:org.springframework.context.annotation.Scope.@Scope指定Spring容器如何创建Bean的实例,S ...
- string部分方法
1.string.lastIndexOf() lastIndexOf 是从string末尾查找,但是返回值仍是首部的位置值. 2.string.replace() 放一个正则匹配会全部替换. 3.st ...
- vue2.0s中eventBus实现兄弟组件通信
在vue1.0中,组件之间的通信主要通过vm.$dispatch沿着父链向上传播和用vm.$broadcast向下广播来实现.然而在vue2.0中,已经废除了这种用法. vuex加入后,对组件之间的通 ...
- Yii框架实现restful 接口调用,增删改查
创建模块modules; 在main.php中配置文件:(1) (2)控制器层: namespace frontend\modules\v1\controllers;use frontend\modu ...
- excel表格中,怎么根据一列重复的数据求对应另一列总和
如下: 求出姓名对应分数总和对应 : 首先复制一份Sheet2 对Sheet1进行操作选中A列姓名 数据->删除重复项->以前选中区域排序->删除重复项 然后删除对应成绩项选中张三对 ...