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" 

run sample on playground

this both legal , idiomatic, there's no need use intermediary buffer.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -