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 成员测试 ...
随机推荐
- AutoFac在MVC中的使用
在asp.net mvc控制器中使用Autofac来解析依赖 如下Controller中使用构造函数依赖注入接口IUserService: public IUserService _IUserServ ...
- 05. .stop、.prevent、.capture、.self、.once、
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Nat Med:单独使用anti-CTLA4治疗前列腺癌效果差的原因
肿瘤细胞能够分泌特定的细胞因子,结合T细胞表面的受体抑制其活性,从而来影响免疫细胞杀死肿瘤细胞的能力.这一类细胞因子被冠名为抗肿瘤免疫反应的“check point”.针对这类check point信 ...
- nyoj308-Substring
#include<stdio.h> #include<string.h> #include<string> #include<math.h> #incl ...
- Python自学:第三章 使用列表中的各个值
bicycles = ['trek','cannondale','redline','specialized'] message = "My first bicycle was a &quo ...
- Police Stations CodeForces - 796D (bfs)
大意: 给定树, 有k个黑点, 初始满足条件:所有点到最近黑点距离不超过d, 求最多删除多少条边后, 使得原图仍满足条件. 所有黑点开始bfs, 贪心删边. #include <iostream ...
- python二进制读写文件
#coding=gbk ''' Created on 2014-5-7 ''' import os.path inputPath = './input.txt' outPath = './out.tx ...
- 【ANT】输入中文格式为乱码
使用ant编译,打出的日志的格式为乱码,加上下面的指定编码后,输出为中文了. 为方便拷贝,将其贴出来 <jvmarg value="-Dfile.encoding=UTF-8" ...
- linux软件管理 软件安装
软件包分类 1) 源代码包 脚本安装包 2) 二进制包 (RPM包,系统默认包) 源码包编译后形成二进制包 JDK的安装 下载jdk的文件解压 tar -zxvf jdk-8u144-linu ...
- Python—字符串的操作
字符串的操作 变量: 变量只能是 字母,数字或下划线的任意组合,但首个字符不能为数字,且不能有空格 以下关键字不能声明为变量: and ,as, assert, break ,class ,conti ...