
Conversion means we take the value of one type and convert it to another type.
Let's try it out in the Go playground
package main
import (
"fmt"
)
var a int
type hotdog int
var b hotdog
func main() {
a = 42
b = hotdog(a) // we can convert the value of a to a value of type hotdog
fmt.Println(a)
fmt.Printf("%T\n", a)
fmt.Println(b)
fmt.Printf("%T\n", b)
}
In other programming languages, this is called casting. We don't call it casting in Go, we call it conversion. If you go to Effective Go and search for "cast" you won't find any results, but if you search for "conversion" you will.
That's the end of this section!
About the author
- DevRel at StackGen | Formerly at Deepfence ,Tenable , Accurics | AWS Community Builder also Docker Community Award Winner at Dockercon2020 | CyberSecurity Innovator of Year 2023 award by Bsides Bangalore | Docker/HashiCorp Meetup Organiser Bangalore & Co-Author of Learn Lightweight Kubernetes with k3s (2019) , Packt Publication & also run Non Profit CloudNativeFolks / CloudSecCorner Community To Empower Free Education reach out me twitterhttps://twitter.com/sangamtwts or just follow on GitHub -> https://github.com/sangam14 for Valuable Resources
Comments
Join the discussionNo comments yet. Be the first to comment.



