Go-syntax representation %T %f %q %p %v %s %d %b golang tutorial

Go-syntax representation %T  %v %s %d %b golang tutorial

 

How to print type of variable ?

You just need to use %t

fmt.printf("%T",my_variable_name)

How to print format string variable ?

You just need to use %s

fmt.printf("%s",my_variable_name)

How to print format integer variable ?

You just need to use %d

fmt.printf("%d",my_variable_name)

How to print format boolean variable ?

You just need to use %t

fmt.Printf(“%t”, true_var)

fmt.Printf(“%t”, false_var)


func main() {
    var truevar bool = true
    fmt.Printf("%t", truevar)
    var falsevar bool = false
    fmt.Printf("%t", falsevar)
}

What is difference between %t & %T ?

%T will show the type of variable i.e boolean, integer,  string, complex.

While the %t will print either true or false.

How to print format float variable ?

You just need to use %f

fmt.printf("%f",my_variable_name)

How to print format double quoted string variable ?

You just need to use %q. Output will be with double quotes around string. if you need without string use %s

fmt.printf("%q",my_variable_name)

How to print format pointer Hex representation with leading 0x variable ?

You just need to use %p

fmt.printf("%p",my_variable_name)

Complete pointer Example with code


func main() {
    var truevar bool = true

    var true_pointer = &truevar

    fmt.Printf("%p", true_pointer)
}

How to print format integer in binary variable ?

You just need to use %b. Convert integer to binary format.

fmt.printf("%b",my_variable_name)

Code Example


func main() {
    var var_int = 234
    fmt.Printf("%b", var_int)
}

How to print format integer variable ?

You just need to use %d

fmt.printf("%d",my_variable_name)

How to print format character representation variable ?

You just need to use %c

fmt.printf("%c",my_variable_name)

code example


func main() {
    var var_int_to_character = 112
    fmt.Printf("%c", var_int_to_character)
}

112 will result in p

111 will result in o

How to print format integer variable ?

You just need to use %d

fmt.printf("%d",my_variable_name)

How to print format integer variable ?

You just need to use %d

fmt.printf("%d",my_variable_name)

How to print format integer variable ?

You just need to use %d

fmt.printf("%d",my_variable_name)
Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: