append()
Appends an element to the slice.
Syntax
slice = append(slice, element)
Description
Appends the new element to the end and returns the RESULT — you must reassign it.
Example
Loading editor…
Expected output
[1 2 3]
When to use?
Growing lists.
Common mistakes
- ⚠️ If the result of append is not reassigned, the addition is lost: s = append(s, x).