我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何使用fmt.Println()扩展变量

I can't expand variables with fmt.Println().

package main
import "fmt"
func main(){
  old := 20
  fmt.Println("I'm %g years old.",old)
}

result =>

I'm %g years old.
20

Use Printf not Println. Use %d for old which is type int. Add a newline.

For example,

package main

import "fmt"

func main() {
    old := 20
    fmt.Printf("I'm %d years old.
", old)
}

Output:

I'm 20 years old.

As the documentation for fmt.Println states, this function does not support format specifiers. Use fmt.Printf instead.

近期文章

  • omitempty不会在JSON中省略接口nil值
  • 无法将所有日志语句写入文件
  • 如何从Golang的Postgres数组中获取切片?
  • 在golang中多次请求后多次关闭响应正文
  • Golang从stdin行读取多个字段
  • 遍历UTF-8字符串时,什么决定了字符的位置?
  • 在Go Postgres中连接到多个数据库的最佳方法
  • 以最小宽度浮动到Golang中的字符串
  • 如果您知道Go中的群组名称,请获取提示
  • Aerospike查询返回最高值
  • Golang虹膜网。 获取HTTP引荐来源网址和用户代理
  • Golang:如何将字符串转换为[] int?
  • 默认结构值
  • 在一些不同的goroutine中共享切片
  • 获取Golang正则表达式中括号内的所有子字符串
  • 防止第三方导入包裹
  • 阵列盖被覆盖
  • Go会修复或共享C的危险隐式->无符号转换吗?
  • 如何使用第三方软件包中未导出的对象作为golang中的返回类型?
  • Golang非阻塞缓冲区

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华