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的更多相关文章

  1. Lintcode208 Assignment Operator Overloading (C++ Only) solution 题解

    [题目描述] Implement an assignment operator overloading method. Make sure that: The new data can be copi ...

  2. Effective C++ 第0章 copy constructor和copy assignment operator

    拷贝构造函数(copy constructor)被用来以一个对象来初始化同类型的另一个对象,拷贝赋值运算符(copy assignment operator)被用来将一个对象中的值拷贝到同类型的另一个 ...

  3. copy constructor和copy assignment operator的区别

    拷贝构造函数(copy constructor)被用来以一个对象来初始化同类型的另一个对象,拷贝赋值运算符(copy assignment operator)被用来将一个对象中的值拷贝到同类型的另一个 ...

  4. Java基础-赋值运算符Assignment Operators与条件运算符Condition Operators

    Java基础-赋值运算符Assignment Operators与条件运算符Condition Operators 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.赋值运算符 表 ...

  5. Default Assignment Operator and References

    We have discussed assignment operator overloading for dynamically allocated resources here . This is ...

  6. 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 ...

  7. Copy constructor vs assignment operator in C++

    Difficulty Level: Rookie Consider the following C++ program. 1 #include<iostream> 2 #include&l ...

  8. How to use base class's assignment operator in C++

    看了android下的代码,好长时间没看了,有个关于C++的知识点不是很清楚,查了下: 如何使用基类中的赋值运算符? 引述自http://stackoverflow.com/questions/122 ...

  9. PythonStudy——运算符优先级 Operator precedence

    运算符优先级 以下所列优先级顺序按照从低到高优先级的顺序:同行为相同优先级. 1 Lambda #运算优先级最低 2 逻辑运算符: or 3 逻辑运算符: and 4 逻辑运算符:not 5 成员测试 ...

随机推荐

  1. sql添加一个list的查询条件

    编程中往往会有需要对某个list的值进行查询的需求,而将一个list作为查询条件,我所知道的有两种方法: 1.for循环遍历,每次循环一个sql,每次查list中一个条件的数据,最后累加 ...(最基 ...

  2. U3D外包团队—技术分享 U3d中获得物体的size

    以size的x方向为例 1:gameObject.renderer.bounds.size.x;//这个值的结果真实反应出有MeshRenderer这个组件的模型的尺寸.不需要再乘以localScal ...

  3. 浅谈StringBuffer

    StringBuffer,由名字可以看出,是一个String的缓冲区,也就是说一个类似于String的字符串缓冲区,和String不同的是,它可以被修改,而且是线程安全的.StringBuffer在任 ...

  4. 使用nginx作为webservice接口代理

    通常情况下,企业并不会直接开放系统接口给到外网,并且在企业内部同样有SOA或者ESB这样的接口统一管理的工具. 那么,大多数情况下,如果需要与外部系统,如云系统,或者其他企业的系统做接口时采取的方式如 ...

  5. 微信小程序城市定位(百度地图API)

    概述 微信小程序提供一些API(地址)用于获取当前用户的地理位置等信息,但无论是wx.getLocation,还是wx.chooseLocation均没有单独的字段表示国家与城市信息,仅有经纬度信息. ...

  6. Makefile 宏定义 -D

    一.GCC编译器中使用:        -D macro=string,等价于在头文件中定义:#define   macro   string. 例如:-D TRUE=true,等价于:#define ...

  7. C++获取网络数据

    1.  获取数据 工具libcurl libcurl主要功能就是用不同的协议连接和沟通不同的服务器.libcurl当前支持http, https, ftp, gopher, telnet, dict, ...

  8. windows server 2016 安装iis

  9. Linux下实现ssh免密认证

    添加域名映射 配置ssh免密登陆 拷贝master服务器公钥至本机 验证master服务器ssh免密登录其余服务器 添加域名映射 打开hosts文件 Vim /etc/hosts 添加域名对象 配置s ...

  10. ui自动化:python+appium----环境搭建

    前言: appium可以说是app最火的一个自动化框架,它的主要优势是支持android和ios,另外脚本支持java和python.以下为python+appium的安装教程... 环境准备... ...