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', ...
随机推荐
- 在IDEA中代码自动提示第一个字母大小写必须匹配的解决
在IDEA中代码自动提示第一个字母大小写必须匹配的解决 学习了:http://blog.csdn.net/babys/article/details/41775715 setting>Edito ...
- Springmvc Get请求Tomcat、WebLogic中文乱码问题
Springmvc Get请求Tomcat.WebLogic中文乱码问题 学习了:http://www.cnblogs.com/qingdaofu/p/5633225.html http://www. ...
- 【翻译自mos文章】怎么正确的计算一个ip地址的subnet id?
怎么正确的计算一个ip地址的subnet id? 来源于: How to calculate the correct subnet for an interface (文档 ID 1059759.1) ...
- node08---Express框架
一.Express框架 Express框架是后台的Node框架,所以和jQuery.zepto.yui(雅虎的).bootstrap都不一个东西. Express在后台的受欢迎的程度,和jQuery一 ...
- android 处理Back键按下事件
package com.example.keyevent; import android.os.Bundle; import android.view.KeyEvent; import android ...
- NOIP卡常数技巧
NOIP卡常数技巧 https://blog.csdn.net/a1351937368/article/details/78162078 http://www.mamicode.com/info-de ...
- Android ViewPager 动画效果
找到个不错的开源项目:https://github.com/jfeinstein10/JazzyViewPager Android ViewPager 动画效果
- AOJ GRL_1_C: All Pairs Shortest Path (Floyd-Warshall算法求任意两点间的最短路径)(Bellman-Ford算法判断负圈)
题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C All Pairs Shortest Path Input ...
- POJ 3264 Balanced Lineup【线段树】
题意:给出n个数,a1,a2,a3,---,an,再给出q次询问区间al到ar之间的最大值和最小值的差 学习线段树的第一道题目 学习的这一篇 http://www.cnblogs.com/kuangb ...
- swift语言点评二
一.数据类型 1.基础类型的封装 Swift provides its own versions of all fundamental C and Objective-C types, includi ...