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. 如何在nginx容器中使用ping、nslookup、ip、curl 等工具?

    Nginx镜像太精简了,启动一个容器进行测试时,常用的网络工具都没有,可以使用下面的命令进行安装.也可以直接起一个busybox容器进行测试. apt update #ping apt install ...

  2. 使用Rancher的RKE快速部署Kubernetes集群

    简要说明: 本文共涉及3台Ubuntu机器,1台RKE部署机器(192.168.3.161),2台Kubernetes集群机器(3.162和3.163). 先在Windows机器上,将rke_linu ...

  3. Bilinear CNN与 Randomly Wired Neural Network

    最近主要学习了两篇论文以及相关的代码. 1.Bilinear CNN 这篇论文主要是在细粒度分类上应用的,在全连接层之前,在所有的卷积计算完成之后,进行的Bilinear计算,关键的代码如下: def ...

  4. Mysql按周,按月,按日,按小时分组统计数据

    按周   select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks;   ...

  5. 92. Reverse Linked List II 反转链表 II

    网址:https://leetcode.com/problems/reverse-linked-list-ii/ 核心部分:通过a.b.c三个变量之间的相互更新,不断反转部分链表 然后将反转部分左右两 ...

  6. idea中springboot项目程序入口右键不显示run as的原因

    今天在idea中导入了springboot的项目,但是在程序的入口处右键单击没有出现run  as 的程序启动方式,主要原因在于idea中右面的maven projects中没加载项目,需要点击“+“ ...

  7. unity5.x中的关节和布料

    关节 布料 关节 铰链关节(Hinge     Joint):将两个物体以链条的形式绑在一起,当力量过大超过链条的固定力矩时,两个物体就会产生相互的拉力. 固定关节(Fixed     Joint): ...

  8. 【转载】GET和POST两种基本请求方法的区别

    原文地址:http://www.cnblogs.com/logsharing/p/8448446.html GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一 ...

  9. firewall-cmd.man

    FIREWALL-CMD(1) firewall-cmd FIREWALL-CMD(1) NAME firewall-cmd - firewalld command line client SYNOP ...

  10. cocos2d-x学习笔记(贪吃蛇代码)

    方向键控制蛇运动:上↑:右→:下↓:左←. 百度网盘链接:https://pan.baidu.com/s/1c1FSXaw 提取密码:u1kr