# 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