var (ix, s) = (1, "One") // can use let or var here
可以通过元组安全地实现变量值的互换:
var s1 = "Hello"
var s2 = "world"
(s1, s2) = (s2, s1) // now s1 is "world" and s2 is "Hello"
全局函数
swap
能以更加通用的方式实现值的互换。
要想忽略掉其中一个赋值,请在接收元组中使用下划线表示:
let ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.