Go 语言中的打印格式列表

2024-03-25

只是想知道使用 fmt 包的功能的打印格式列表。

例如:

%v 用于打印值。 %T 可以打印值的类型。

还有什么?


“动词”格式列表可在fmt 包的文档 http://golang.org/pkg/fmt/ :

General:

%v  the value in a default format.
    when printing structs, the plus flag (%+v) adds field names
%#v a Go-syntax representation of the value
%T  a Go-syntax representation of the type of the value
%%  a literal percent sign; consumes no value

Boolean:

%t  the word true or false

Integer:

%b  base 2
%c  the character represented by the corresponding Unicode code point
%d  base 10
%o  base 8
%q  a single-quoted character literal safely escaped with Go syntax.
%x  base 16, with lower-case letters for a-f
%X  base 16, with upper-case letters for A-F
%U  Unicode format: U+1234; same as "U+%04X"

浮点和复数成分:

%b  decimalless scientific notation with exponent a power of two,
    in the manner of strconv.FormatFloat with the 'b' format,
    e.g. -123456p-78
%e  scientific notation, e.g. -1234.456e+78
%E  scientific notation, e.g. -1234.456E+78
%f  decimal point but no exponent, e.g. 123.456
%g  whichever of %e or %f produces more compact output
%G  whichever of %E or %f produces more compact output

字符串和字节切片:

%s  the uninterpreted bytes of the string or slice
%q  a double-quoted string safely escaped with Go syntax
%x  base 16, lower-case, two characters per byte
%X  base 16, upper-case, two characters per byte

Pointer:

%p  base 16 notation, with leading 0x

其他标志:

+   always print a sign for numeric values;
    guarantee ASCII-only output for %q (%+q)
-   pad with spaces on the right rather than the left (left-justify the field)
#   alternate format: add leading 0 for octal (%#o), 0x for hex (%#x);
    0X for hex (%#X); suppress 0x for %p (%#p);
    print a raw (backquoted) string if possible for %q (%#q);
    write e.g. U+0078 'x' if the character is printable for %U (%#U).
' ' (space) leave a space for elided sign in numbers (% d);
    put spaces between bytes printing strings or slices in hex (% x, % X)
0   pad with leading zeros rather than spaces
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Go 语言中的打印格式列表 的相关文章

  • 将接口转换为结构体

    type SipField interface Info id name defaultValue string length int type Field string func f Field Get string return str
  • 处理变量的范围:内部循环

    作为一名直接进入 Go 的 JS 开发者 如果长度超过commits不止一个 我没有太多时间来完成这件事 而且我搜索的时间比我希望的要长 关于如何重组它或让它发挥作用有什么想法吗 case github PushPayload push p
  • 为什么空切片有 24 个字节?

    我想了解创建空切片时会发生什么make int 0 我执行此代码进行测试 emptySlice make int 0 fmt Println len emptySlice fmt Println cap emptySlice fmt Pri
  • .NET 电话号码解析库

    有谁知道 NET 的通用电话号码解析库吗 理想情况下 我正在寻找类似于 Ruby 的东西Phone http github com carr phone图书馆 我会选择 Google libphonenumber 库的 C 端口 https
  • 如何更新任意go结构的所有字符串字段?

    我尝试编写一个函数来更新所有字符串字段随意的结构体 像这样 type Student struct Name string Age int func SetStringField obj interface reflect ValueOf
  • 在 Go 中将 float 转换为 int 时如何舍入到最近的 int

    将 float 转换为 int 时 小数点将被丢弃 有什么干净的方法可以将其四舍五入到最接近的整数 x int 3 6 应等于 4 而不是 3 int f 0 5 如果 gt 5 将导致向上舍入
  • go:找到模块但不包含包

    我正在尝试安装 go 的网络包 但收到 不包含包错误 终端截图 我咨询过 go 模块 latest 已找到但不包含包 https stackoverflow com questions 62974985 go module latest f
  • 将具有联合字段的 C 结构映射到 Go 结构

    我从 Go 中的某些 WinApi 的系统调用中获取结果 我可以轻松地从 C 代码映射简单的结构 但是如何处理如下所示的 C 结构 typedef struct SPC LINK DWORD dwLinkChoice define SPC
  • IntelliJ 2017.1.2 GOLANG 调试不适用于包中的断点

    我的应用程序由一个 main go 文件和一些包组成 当在 main go 中命中断点时 IntelliJ 按预期工作 显示变量值等 但是 当在不同的包中设置断点时 除了被命中之外 不会显示任何变量 并且不会跳过 进入功能按预期工作 被击中
  • mysql 查询中的 golang 切片,带有 where in 子句

    我正在运行以下查询 但只获取第一个 id 值 select from table where table id in 1 2 3 4 5 6 7 9 11 13 14 15 17 and table deleted at is null 我
  • 将秒整数转换为 HH:MM,iPhone

    我正在为此苦苦挣扎 我想以 HH MM 格式在标签中显示一个以秒为单位的值 我在互联网上搜索了很长时间并找到了一些答案 但要么没有完全理解它们 要么它们看起来像是一种奇怪的做我想做的事情的方式 如果有人能帮助我解决这个问题 那就太好了 请记
  • foo.Name undefined(类型接口{}没有字段或方法名称)

    我使用本机 golang 包 container list 来管理堆栈中的 inotify 事件 当我访问堆栈的项目时 我的类型失败 我认为 import golang org x exp inotify container list lo
  • formatFloat :将浮点数转换为字符串[重复]

    这个问题在这里已经有答案了 http golang org pkg strconv http golang org pkg strconv http play golang org p 4VNRgW8WoB http play golang
  • golang:使用 gin 路由器服务 net.Conn

    我有一个处理传入 TCP 连接的函数 func Handle conn net Conn error 另外 我有一个初始化的 gin 路由器 带有已实现的句柄 router gin New router GET router POST Th
  • 在 Go 中修改导入的库

    我的问题 弹性节拍 https www elastic co products beats是一个用 Go 编写的日志传送程序的开源项目 它具有多种日志输出功能 包括控制台 Elasticsearch 和 Redis 我想将我自己的输出添加到
  • Clang 格式将 if 语句体拆分为多行

    我有以下 cpp 文件 void call long function name bool void sf bool int main bool test true if test call function name test if te
  • golang从sdin扫描一行数字

    我正在尝试从标准输入读取输入 3 2 1
  • Golang 网络爬虫 NTLM 身份验证

    Golang 网络抓取工具需要从经过 NTLM 验证的网页中提取信息 有了有效的用户名和密码 网络抓取工具如何与服务器进行 NTLM 4 次握手 以获得对后面受保护网页的访问权限 url username password http www
  • 如何顺序运行 golang 测试?

    当我跑步时go test 我的输出 FAIL TestGETSearchSuccess 0 00s Location drivers api test go 283 Error Not equal 200 expected 204 actu
  • 使用 google.protobuf.Timestamp 在 Go 中解析带有时区偏移的日期时间戳

    我正在创建一个将使用 GRPC 和 protobuf 的 Go 应用程序 我的 RPC 服务应获取包含类型的消息google protobuf Timestamp 解析它并最终将其保存在数据库中或对其执行更多操作 我对什么被认为是该类型的有

随机推荐

  • 如何在我的 asp.net Web 应用程序中调用嵌入 dll 中的 javascript 文件?

    在我为我的 asp net 构建的库中 是否可以将 javascript 文件作为嵌入资源嵌入 并且仍然能够通过 URL 调用和 或脚本标记检索它 而无需创建辅助 ashx 只是为了加载 javascript 这是完全有可能的 谷歌很快就想
  • 使用 HTML 标签解析 JSON 数组以输出纯 HTML

    过去两天我一直在谷歌搜索这个 我无法完美地完成它 我认为 这属于或可以由某些模板引擎完成 但是 我无法找到所谓的引擎 我有这个JSON array我想将其解析回来或将其转换为纯 HTML 以将其输出到浏览器 tag figure child
  • Bash:如何在算术表达式中进行变量扩展?

    尝试编写一个简单的 bash 脚本来提供帮助 在我的部署过程中 我遇到了一个令人困惑的错误 bin bash WEEKDAY date u echo WEEKDAY DAYS TO WEDNESDAY 3 WEEKDAY echo DAYS
  • VS2010 debug/release.config 不起作用

    我的方法有点问题web debug config and web release config files 更具体地说 我的网页只会使用默认的web config文件 并完全忽略debug and release文件 不仅当我在本地运行项目
  • NoReverseMatch at / urlresolvers 的反向错误,get_absolute_url()

    函数 get absolute url 中 url reverse 出错 无法反转每个模型 serial slug 中的 url 但 url 本身存在 这是主 url py from django conf urls import incl
  • Android并发使用[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 Android 有许多不同的便利措施可以在单独的线程上同时执行代码 但我不确定何时应该使用每种方法 或者这些不同方法的最佳实践是什么
  • 打印数组值两次 / php 和 pdo

    我收到 field value 两次 但为什么呢 正常的结构是
  • 在ggplot2散点图中使用伪彩色来表示密度

    有人知道如何创建像屏幕截图中那样的图表吗 我试图通过调整 alpha 来获得类似的效果 但这会使异常值几乎看不见 我只从一个名为 FlowJo 的软件中知道这种类型的图 这里他们将其称为 伪彩色点图 不确定这是否是官方术语 我想专门在 gg
  • ng-click 在动态创建的内容中不起作用

    我在 Angular 中有这个功能 我在其中添加了一个带有 ng click 的新幻灯片 var addSlide function scope slideIndex event slideIndex var slider angular
  • 通过 PHP 批量插入 MySQL 数据库会跳过名称

    我目前正在开发一个跟踪程序 可以同时跟踪数百个用户 但我遇到了一个有点烦人的问题 我让用户插入数据库的方法是通过 html 文本区域 然后将它们作为参数发送 总是有大约 60 人中的 7 人 也总是相同的名字 被插入到数据库中 但它没有插入
  • 创建具有不同单元格类型的分组 UITableview

    我需要创建一个分组的 uitableview 其中包括一些部分以及每个部分中可能不同的单元格类型 我正在尝试创建类似旧的 foursquare 应用程序 用户页面 包括 排行榜 朋友建议 朋友 统计数据 最探索的类别 部分 我对 ios 编
  • ASP.NET MVC 客户端验证

    我热衷于使用 ASP NET MVC 但我希望改进的领域之一是客户端验证 我知道最新版本 预览版 5 有很多用于验证的新功能 但它们似乎都是在页面发布之后 我看过一篇有趣的文章史蒂夫 桑德森 http blog codeville net
  • 没有这样的模块 Crashlytics - Pod 似乎丢失了

    我经常收到错误 No such module Crashlytics 我通常会花费数小时清理构建文件夹 重新安 装所有内容 运行 pod install 等来解决该问题 但我对此感到厌倦 并希望一劳永逸地解决该问题 我的 podfile 包
  • Mongoose 验证外键(参考)

    我尝试了几种不同的方法来验证 Mongoose 中的外键 但无法弄清楚 我有一个这样的架构 Doctors js var schema mongoose Schema email type String module exports mon
  • 使用 Django 上传表单清空 Request.FILES

    尝试使用非常简单的形式将文件上传到新的类实例中 我希望这两个文件都在request FILES但它是空的 我在捆绑的开发服务器上 被困在这里并解决了所有相关问题 wayfinder map media file request FILES
  • 复选框样式并使其选中

    从数据库检索到的复选框太长了 它是向下的 有什么办法使它成为四层 单击 所有字段 复选框时 必须选中所有复选框 这要怎么做呢 我的代码 protected function getConfigForm sql SELECT id order
  • 检查字符串中的字符是否都是唯一的

    我正在尝试使用 JS 通过数组来解决这个问题 var str abcdefgh for i 0 i lt 255 i arr i false function check for i 0 i lt str length i if arr s
  • 如何从实体管理器获取 jpa 数据源属性

    大家好 我想知道是否可以通过实体管理器获取数据库连接属性 我的 persistence xml 看起来像这样
  • 暂停事件在 PhoneGap iPhone 中无法正常工作?

    这是我的代码 This is an event that fires when a PhoneGap application is put into the background document addEventListener paus
  • Go 语言中的打印格式列表

    只是想知道使用 fmt 包的功能的打印格式列表 例如 v 用于打印值 T 可以打印值的类型 还有什么 动词 格式列表可在fmt 包的文档 http golang org pkg fmt General v the value in a de