Tuple assignment
It is often useful to swap the values of two variables. With conventional assignments, you have to use a temporary variable. This solution is cumbersome; tuple assignment is more elegant:

The left side is a tuple of variables; the right side is a tuple of expressions. Each value is assigned to its respective variable. All the expressions on the right side are evaluated before any of the assignments. The number of variables on the left and the number of values on the right have to be the same:

More generally, the right side can be any kind of sequence (string, list or tuple). For example, to split an email address into a user name and a domain, you could write:

from Thinking in Python
Tuple assignment的更多相关文章
- 《python解释器源码剖析》第5章--python中的tuple对象
5.0 序 我们知道对于tuple,就相当于不支持元素添加.修改.删除等操作的list 5.1 PyTupleObject对象 tuple的实现机制非常简单,可以看做是在list的基础上删除了增删改等 ...
- [python] File path and system path
1. get files in the current directory with the assum that the directory is like this: a .py |----dat ...
- Think Python - Chapter 12 Tuples
12.1 Tuples are immutable(元组是不可变的)A tuple is a sequence of values. The values can be any type, and t ...
- Think Python Glossary
一.The way of the program problem solving: The process of formulating a problem, finding a solution, a ...
- Python in minute
Python 性能优化相关专题: https://www.ibm.com/developerworks/cn/linux/l-cn-python-optim/ Python wikipedi ...
- The Go Programming Language. Notes.
Contents Tutorial Hello, World Command-Line Arguments Finding Duplicate Lines A Web Server Loose End ...
- [Python] 07 - Statements --> Functions
故事背景 一.阶级关系 1. Programs are composed of modules.2. Modules contain statements.3. Statements contain ...
- 10 The Go Programming Language Specification go语言规范 重点
The Go Programming Language Specification go语言规范 Version of May 9, 2018 Introduction 介绍 Notation 符号 ...
- Python中的赋值语法
Python中复制语法有6种 Basic Form >>>spam = 'spam' Tuple assignment >>>spam, ham = 'spam', ...
随机推荐
- poj 3259 bellman最短路推断有无负权回路
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36717 Accepted: 13438 Descr ...
- LeetCode OJ 215. Kth Largest Element in an Array 堆排序求解
题目链接:https://leetcode.com/problems/kth-largest-element-in-an-array/ 215. Kth Largest Element in an A ...
- 安卓中经常使用控件遇到问题解决方法(持续更新和发现篇幅)(在textview上加一条线、待续)
TextView设置最多显示30个字符.超过部分显示...(省略号),有人说分别设置TextView的android:signature="true",而且设置android:el ...
- 小贝_mysql三种子查询
mysql三种子查询 简要: 一.三种子查询 二.三种子查询理解模型 一.mysql 三种子查询 where子查询.from子查询.exists子查询 二.理解模型: 2.1.一个好的模型,便于我们去 ...
- Hadoop实战:使用Combiner提高Map/Reduce程序效率
好不easy算法搞定了.小数据測试也得到了非常好的结果,但是扔到进群上.挂上大数据就挂了.无休止的reduce不会结束了. .. .. .... .. ... .. ================= ...
- Win10使用VMware虚拟机安装ubuntu
Win10专业版自带有虚拟机安装工具Hyper-V,也可以使用其他如VMware工具安装,也挺方便. 所需工具: 1. VMware-workstation 下载链接: http://rj.bai ...
- c:\Windows\System32\drivers\etc\hosts的作用
c:\Windows\System32\drivers\etc\hosts 是域名解析文件. 可以直接用记事本打开.将IP地址重定向. 格式为:ip地址-空格-域名 可以将一个域名重新定向到一个IP ...
- 133.throw机制 抛出类类型
#include <iostream> using namespace std; //try尝试执行,抛出throw,throw之后语句不再执行 //catch处理throw的异常 voi ...
- hbase的优化(全)
高可用 在HBase中Hmaster负责监控RegionServer的生命周期,均衡RegionServer的负载,如果Hmaster挂掉了,那么整个HBase集群将陷入不健康的状态,并且此时的工作状 ...
- double int 类型的区别
内部组织格式不同: po [NSString stringWithFormat:@"%d", f] 107886912 (lldb) po [NSString stringWith ...