
Inside a function, the := short assignment statement can be used in place of a var declaration with implicit type.
Outside a function, every statement begins with a keyword (var, func, and so on) and so the := construct is not available.
package main
import "fmt"
func main() {
a := 10
b := "golang"
c := 4.17
d := true
e := "Hello"
f := `Do you like my hat?`
g := 'M'
fmt.Printf("%v \n", a)
fmt.Printf("%v \n", b)
fmt.Printf("%v \n", c)
fmt.Printf("%v \n", d)
fmt.Printf("%v \n", e)
fmt.Printf("%v \n", f)
fmt.Printf("%v \n", g)
}
%v the value in a default format
%v will give you the values of variable
package main
import "fmt"
func main() {
a := 10
b := "golang"
c := 4.17
d := true
e := "Hello"
f := `Do you like my hat?`
g := 'M'
fmt.Printf("%T \n", a)
fmt.Printf("%T \n", b)
fmt.Printf("%T \n", c)
fmt.Printf("%T \n", d)
fmt.Printf("%T \n", e)
fmt.Printf("%T \n", f)
fmt.Printf("%T \n", g)
}
%T a Go-syntax representation of the type of the value
in this above go program %T provide you the type of variable
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.



