# in python, also works in ES6 s1 = 3 s2 = 4 # Quick swap s1, s2 = s2, s1
是指仅仅在真正须要执行的时候才计算表达式的值。javascript
if x and y
,在x为false的状况下y表达式的值将再也不计算。而对于if x or y
,当x的值为true的时候将直接返回,再也不计算y的值。所以编程中能够利用该特性:
and
逻辑中,将小几率发生的条件放在前面;or
逻辑中,将大几率发生的时间放在前面,有助于性能的提高。def fib(): a,b = 0,1 while True: yield a a,b = b,a+b fib_gen = fib() for i in range(30): print(fib_gen.next())
# In python # Destruction li = (1, 2, 3) a, b, c = li print(b) li1 = [1, 2, 3, 4, 5, 6] c, *_, d = li1
// In ES6 // we have an array with the name and surname let arr = ["Ilya", "Kantor"] // destructuring assignment let [firstName, surname] = arr; alert(firstName); // Ilya alert(surname); // Kantor
Get details from site ES6 destructuring assignment.java