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. 赵雅智_使用SQLiteDatabase操作SQLite数据库及事务

    知识点具体解释:http://blog.csdn.net/zhaoyazhi2129/article/details/9025995 详细代码: MainActivity.java package c ...

  2. HDU 5416 CRB and Tree (2015多校第10场)

    欢迎參加--每周六晚的BestCoder(有米!) CRB and Tree Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536 ...

  3. HDU 1040.As Easy As A+B【排序】【如题(水!水!水!)】【8月24】

    As Easy As A+B Problem Description These days, I am thinking about a question, how can I get a probl ...

  4. Oracle 12c agent install for windows

    在Oracle EM12c 中部署agent的方法分两种,一种是通过EM12c的控制台通过ssh直接把agent"推送"安装到被管理端.这样的方法在linux平台的OMS和被管理端 ...

  5. 在GitHub上使用Hexo搭建静态博客

    搭建静态博客须要一个前提是电脑上有安装git而且有github帐号,这个不懂能够看廖雪峰先生的git教程 1.下载nodejs.在官网上能够下载 2.使用git进入你新建的一个目录,输入命令 npm ...

  6. xBIM 基础16 IFC的空间层次结构

    系列目录    [已更新最新开发文章,点击查看详细]  本篇介绍如何从文件中检索空间结构.IFC中的空间结构表示层次结构的嵌套结构,表示项目,站点,建筑物,楼层和空间.如果您查看IFC文档, 您会发现 ...

  7. ubuntu下创建文件夹快捷方式

    title: ubuntu下创建文件夹快捷方式 toc: false date: 2018-09-01 17:22:28 categories: methods tags: ubuntu 快捷方式 s ...

  8. winforms控件

     我们在开发窗体应用时,控件是必不可少的今天我们就来认识一下控件 在认识控件之前还要先来认识一下窗体具体如下: 认识窗体和控件 窗体                                   ...

  9. C++之虚函数表

    本文引自:http://songlee24.github.io/blog/2014/09/02/c-plus-plus-jin-jie-zhi-xu-han-shu-biao/ C++通过继承(inh ...

  10. HTML基础——网站首页显示页面

    1.表格标签: border设置边框,align设置位置(居中等),bgcolor设置背景颜色,cellspacing设置边框之间的空隙,cellpadding设置边框与里面内容的间距. table表 ...