Skip to main content

Command Palette

Search for a command to run...

Short Variable Declarations

Updated
1 min readView as Markdown
Short Variable Declarations
S
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

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)
}

Run

%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)
}

RUN

%T a Go-syntax representation of the type of the value in this above go program %T provide you the type of variable

26 views

More from this blog

C

CloudNativeFolks Community

140 posts

CloudNativeFolks is non profit community that empower and educate about cloud native technology !