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)

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

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

<div>
<div>func main() {</div>
<div>    var truevar bool = true</div>
<div></div>
<div>    var true_pointer = &amp;truevar</div>
<div></div>
<div>    fmt.Printf("%p", true_pointer)</div>
<div>}</div>
</div>

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

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

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

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

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: