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

  1. 《python解释器源码剖析》第5章--python中的tuple对象

    5.0 序 我们知道对于tuple,就相当于不支持元素添加.修改.删除等操作的list 5.1 PyTupleObject对象 tuple的实现机制非常简单,可以看做是在list的基础上删除了增删改等 ...

  2. [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 ...

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

  4. Think Python Glossary

    一.The way of the program problem solving: The process of formulating a problem, finding a solution, a ...

  5. Python in minute

    Python 性能优化相关专题:    https://www.ibm.com/developerworks/cn/linux/l-cn-python-optim/   Python wikipedi ...

  6. The Go Programming Language. Notes.

    Contents Tutorial Hello, World Command-Line Arguments Finding Duplicate Lines A Web Server Loose End ...

  7. [Python] 07 - Statements --> Functions

    故事背景 一.阶级关系 1. Programs are composed of modules.2. Modules contain statements.3. Statements contain ...

  8. 10 The Go Programming Language Specification go语言规范 重点

    The Go Programming Language Specification go语言规范 Version of May 9, 2018 Introduction 介绍 Notation 符号 ...

  9. Python中的赋值语法

    Python中复制语法有6种 Basic Form >>>spam = 'spam' Tuple assignment >>>spam, ham = 'spam', ...

随机推荐

  1. 从零開始学android<TabHost标签组件.二十九.>

    TabHost主要特点是能够在一个窗体中显示多组标签栏的内容,在Android系统之中每一个标签栏就称为一个Tab.而包括这多个标签栏的容器就将其称为TabHost.TabHost类的继承结构例如以下 ...

  2. ORACLE里锁的几种模式

    0:none  1:null 空  2:Row-S 行共享(RS):共享表锁  3:Row-X 行专用(RX):用于行的修改  4:Share 共享锁(S):阻止其他DML操作  5:S/Row-X ...

  3. @Query Annotation in Spring Data JPA--转

    原文地址:http://javabeat.net/spring-data-jpa-query/ In my previous post on Spring Data, I have explained ...

  4. Android UnitTest FrameWork

    Android test suites基于Junit,可以直接使用Junit测试不使用android api的class,也可以使用android的Junit extensions测试android ...

  5. 继续ubuntu和遇到的easybcd的坑

    找了很多教程,反复斟酌https://www.zhihu.com/question/34611974 个人感觉前方还有大坑无数.unbuntu四个分区系列——65%根目录,25%home目录,交换分区 ...

  6. BootStrap学习(三)——重写首页之导航栏和轮播图

    1.按钮 1)帮助文档:http://v3.bootcss.com/css/#buttons 2).btn-lg..btn-sm..btn-xs可以设置按钮的不同尺寸 3).active类设置按钮的激 ...

  7. windows py-faster-rcnn配置

    [原创帖!转载请注明] windows faster-rcnn安装一直会出现各种错误,本人在实验室电脑成功安装后,在自己电脑上同样的安装步骤也成功.所以做个总结,希望对大家有帮助. 一:安装环境 1. ...

  8. STM8S汇编代码分析

    转载:http://blog.csdn.net/u010093140/article/details/50021897使用STVD建立完汇编工程项目之后(具本建立方法可以看我的另一篇博文http:// ...

  9. PIC c语言

    rom类型,对于占内存的类型定义为rom类型,跟标准c中的const不一样,const跟rom不能通用,否则编译会报type qualifier dismatch 有些变量定义成了rom型,那么如果改 ...

  10. How Javascript works (Javascript工作原理) (七) WebAssembly 对比 JavaScript 及其使用场景

    个人总结: 1.webworkers实现了用多线程浏览器来进行多线程操作js的能力. 2.web workers不能操作dom,window,document等对象,一般用于cpu计算型的任务.   ...