go - Best way to swap elements in golang slice? -
is possible swap elements in python?
a,b = b,a
or have use:
temp = a = b b = temp
yes, possible. assuming a
, b
have same type, example provided work fine. example:
a, b := "second", "first" fmt.println(a, b) // prints "second first" b, = a, b fmt.println(a, b) // prints "first second"
this both legal , idiomatic, there's no need use intermediary buffer.
Comments
Post a Comment