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. Could not connect to SMTP host: localhost, port: 25;

    1.错误描写叙述 DEBUG: setDebug: JavaMail version 1.3.3 DEBUG: getProvider() returning javax.mail.Provider[ ...

  2. 纯文本中识别URI地址并转换成HTML

    问题 有一段纯文本text, 欲将其插入DOM节点div中. text中可能有超链接, 邮件地址等. 假设有, 识别之. 分析 假设仅仅是纯文本, 插入div中, 仅仅要将div.innerText设 ...

  3. 微信企业号开发:微信用户信息和web网页的session的关系

         微信企业号的用户是须要验证的,因此能关注企业号的用户事实上就是已经通过验证的用户.但企业应用中打开一个网页,在这个网页中怎样依据微信用户的信息创建web应用中最长使用的session呢?微信 ...

  4. webserver的作用!

    常见的webserver:Apache和Nginx(linux平台) IIS(window平台) 非常多小公司小项目眼下不一定使用了webserver,由于流量下,单台应用server能够支撑. 实际 ...

  5. 对苹果“五仁”编程语言Swift的简单分析

    对苹果"五仁"编程语言Swift的简单分析 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvUHJvdGVhcw==/font/5a6L5 ...

  6. [BLE--Link Layer]设备蓝牙地址

    简述 不论什么网络设备而言,都会有自己独特的一个MAC地址,不然在设备量较大的情况下非常可能造成通信的混乱.蓝牙是无线通信中使用非常广泛的技术.当然其蓝牙地址也是相当的重要的了. 蓝牙地址简述 种类划 ...

  7. zzulioj--1799--wrz的压岁钱(贪心)

     1799: wrz的压岁钱 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 407  Solved: 71 SubmitStatusWeb Boa ...

  8. C#.Net版本自动更新程序及3种策略实现

    C#.Net版本自动更新程序及3种策略实现 C/S程序是基于客户端和服务器的,在客户机编译新版本后将文件发布在更新服务器上,然后建立一个XML文件,该文件列举最新程序文件的版本号及最后修改日期.如程序 ...

  9. 你不知道的JavaScript演示代码Github地址

    你不知道的JavaScript博文相关代码托管至Github,每次写完博客会把代码提交上去. 代码地址:https://github.com/rongbo-j/you-dont-know-js 点击D ...

  10. NOIp模拟赛三十

    心态崩了的一天 先Orz yrx 开场五分钟yrx大吼一声:“这B题不是原题吗” hjw:“对哦好像我也做过哦” 过了十分钟yrx又大吼一声:“这C题我也做过啊,洪水那题啊” 于是 像我这种傻逼A题一 ...