<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43" -->

---
title: Sliced by Go’s Slices | daily.dev
description: A short post about a surprising Go behavior: when you expand a slice using variadic syntax (s...) and the called function captures it as a variadic parameter,...
canonical: https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Sliced by Go’s Slices | daily.dev
og:description: A short post about a surprising Go behavior: when you expand a slice using variadic syntax (s...) and the called function captures it as a variadic parameter,...
og:url: https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43
og:image: https://api.daily.dev/og/posts/sADBHhK43.png
og:image:alt: Sliced by Go’s Slices
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Sliced by Go’s Slices

**[Lobsters](https://daily.dev/sources/lobsters)** · 2 min read · 1 upvotes · 1 comments

## Summary

A short post about a surprising Go behavior: when you expand a slice using variadic syntax (s...) and the called function captures it as a variadic parameter, both the caller and callee share the same underlying array. Mutating elements inside the function mutates the original slice. This is contrasted with Python, where *args creates an immutable tuple and **kwargs creates a copy, preventing such aliasing bugs.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://ohadravid.github.io/posts/2026-02-go-sliced/>

## Community discussion

Top comments from developers on daily.dev.

**@khauma** · 0 upvotes

> ```import "fmt"
>
> func PrintSquares(nums ...int) {
> 	copiedNums := make([]int, len(nums))
> 	copy(copiedNums, nums)
>
> 	for i, n := range copiedNums {
> 		copiedNums[i] = n * n
> 	}
> 	fmt.Printf("1 %v\n", copiedNums)
> }
>
> func main() {
> 	nums := []int{1, 2, 3}
> 	PrintSquares(nums...)
> 	fmt.Printf("2 %v\n", nums)
> }
>
> ```

## Similar posts on daily.dev

- [Going Backward](https://daily.dev/posts/going-backward-oufacah0y) · Anton Zhiyanov · 23 upvotes · 3 comments

---

Tags: [#python](https://daily.dev/tags/python), [#golang](https://daily.dev/tags/golang)

[View this post on daily.dev](https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Sliced by Go’s Slices","url":"https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43"},"datePublished":"2026-02-27T12:19:29.412Z","dateModified":"2026-02-27T12:19:47.184Z","description":"A short post about a surprising Go behavior: when you expand a slice using variadic syntax (s...) and the called function captures it as a variadic parameter,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4bf0c278e828e48f6b3b20eeb76a191c?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4bf0c278e828e48f6b3b20eeb76a191c?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"python,golang","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"Sliced by Go’s Slices"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/sliced-by-go-s-slices-sadbhhk43","comment":[{"@type":"Comment","text":"func PrintSquares(nums ...int) {\n\tcopiedNums := make([]int, len(nums))\n\tcopy(copiedNums, nums)\n\n\tfor i, n := range copiedNums {\n\t\tcopiedNums[i] = n * n\n\t}\n\tfmt.Printf(&quot;1 %v\\n&quot;, copiedNums)\n}\n\nfunc main() {\n\tnums := []int{1, 2, 3}\n\tPrintSquares(nums...)\n\tfmt.Printf(&quot;2 %v\\n&quot;, nums)\n}","datePublished":"2026-06-26T14:00:04.921Z","dateModified":"2026-06-26T14:00:42.444Z","url":"https://daily.dev/posts/sADBHhK43#c-kDmgQAVF6","author":{"@type":"Person","name":"Kahlil Wallace","url":"https://daily.dev/khauma","image":"https://media.daily.dev/image/upload/s--QvppE9Ip--/f_auto/v1767378558/avatars/avatar_7eQFeSQRDx0muV3n92gxT?_a=BAMAK+ZW0"}}]}
```

