打印值及其数据类型

package main
import "fmt"

func main() {
    anInt := 1234
    fmt.Printf("Data Type:", "%T
", anInt, "Value is:", anInt)
}

Ouput:

Data Type:%!(EXTRA string=%T
, int=1234, string=Value is:, int=1234)

But Expected Output:

Data Type: int, Value is: 1234

I have tried using import reflect still not the expected result

Data Type:%!(EXTRA *reflect.rtype=int, string=Value is:, int=1234)

Package fmt

import "fmt"

func Printf

func Printf(format string, a ...interface{}) (n int, err error)

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.


It's a single format string. For example,

package main

import "fmt"

func main() {
    anInt := 1234
    fmt.Printf("Data Type: %T
Value is: %v
", anInt, anInt)
    // or, concise version
    fmt.Printf("Data Type: %[1]T
Value is: %[1]v
", anInt)
}

Output:

Data Type: int
Value is: 1234
Data Type: int
Value is: 1234