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. WebApi实现验证授权Token,WebApi生成文档等(转)

    using System; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Security; ...

  2. 浅谈JS中的原型对象和原型链

    我们知道原型是一个对象,其他对象可以用它实现属性继承,除了prototype,又有__proto__ 1. prototype和__proto__的区别 prototype是函数才有的属性      ...

  3. python中实现并发的手段之 协程

    几种实现并发的手段 进程 启动多个进程 进程之间是由操作系统负责调用线程 启动多个线程 真正被CPU执行的最小单位实际是线程 开启一个线程 创建一个线程 寄存器 堆栈 关闭一个线程协程 本质上是一个线 ...

  4. git创建分支提交到远程分支步骤

    git创建分支提交到远程分支步骤 step1,在本地新建分支() git branch newbranch step2:把本地分支push到远程 git push origin newbranch s ...

  5. day19_python_1124

    .01 昨日内容回顾 面向对象:1,将一些相似功能的函数集合到一起 类:具有相同属性和功能的一类事物. 对象:类的具体体现. 2,站在上帝的角度考虑问题,类就是一个公共模板, 类的结构: class ...

  6. navicat连接Oracle数据库

    记录一下navicat连接Oracle数据库过程: 一.根据自己版本去Oracle官网下载instantclient 地址:https://www.oracle.com/technetwork/top ...

  7. 给学习Linux系统小白的两三个建议

    前段时间看过一个针对国内Linux使用情况的调研表,有了不少感慨.现在听说过linux,会一点linux基本操作的人多如牛毛,然而真正能用linux做一点事情的确少之又少.无论是公司还是学校,办公基本 ...

  8. vue-router进阶-1-导航守卫

    导航守卫主要用来通过跳转或取消的方式守卫导航 全局守卫,使用 router.beforeEach 注册一个全局前置守卫 const router = new VueRouter({ ... }) ro ...

  9. SEH X86

    ( windows 提供的异常处理机制实际上只是一个简单的框架,一般情况下开发人员都不会直接用到.我们通常所用的异常处理(比如 C++ 的 throw.try.catch)都是编译器在系统提供的异常处 ...

  10. 用canvas画一个房子

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <script t ...