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 成员测试 ...
随机推荐
- OC的反射机制
反射机制主要是指程序可以访问.检测和修改它本身状态或行为的一种能力.反射机制是指在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法.对于人一个对象,都能够调用这个对象的任意方法和属性.这种 ...
- vue--实例化对象
根目录下的文件,这些是创建vue项目时生成的配置文件 node_modules=> 里面的文件是项目开发过种中的各种依赖,我们暂且不用去深入了解: public=> 主要放的是一些公用的文 ...
- 查找IDEA 项目中的依赖包存放在.m2位置
原因:在maven项目pom.xml中添加依赖,可能由于网络不好,下载不完全,导致再次下载一直报错. 就会导致出现依赖一直报错.
- dropna(thresh=n) 的用法
thresh=n,保留至少有 n 个非 NA 数的行
- javascript里文字选中/选中文字
一.获取/清除选中的文字 //获取选中的文字 document.getElementById("get").onclick = function () { var txt = wi ...
- ceph问题总结
之前测试用ceph总是警告 health HEALTH_WARN pool cephfs_metadata2 has many more objects per pg than average (to ...
- rest_framework 之视图
1. 继承ModelSerilizer,直接指定要序列化的表模型 MySerializers.py from app import models # 继承ModelSerilizer,直接指定要序列化 ...
- NVMe概述
目前企业SSD市场按照接口协议主要分为SATA SSD,PCIe SSD和NVMe SSD,其中SATA SSD沿用了传统的HDD使用的SATA协议,在企业应用和服务器兼容性上具有优势:而PCIe S ...
- linux curl http get 请求中带有中文参数或者特殊字符处理
在使用c++去请求http服务的时候,使用的是著名的curl工具提供的类库 libcurl,但是在使用的过程中发现,如果请求的参数值带了空格或者是参数是中文,会导致响应的回调函数没有被执行,虽然cur ...
- Java集合类框架的最佳实践有哪些?
1.根据应用需要正确选择要使用的集合类型对性能非常重要,比如:假如知道元素的大小是固定的,那么选用Array类型而不是ArrayList类型更为合适. 2.有些集合类型允许指定初始容量.因此,如果我们 ...