当前位置: 首页 > 面试题库 >

Go lang中的打印格式列表

沈树
2023-03-14
问题内容

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

例如,例如:

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

还有什么?


问题答案:

fmt软件包
文档中
提供了“动词”格式的列表:

一般:

%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

布尔值:

%t  the word true or false

整数:

%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

指针:

%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


 类似资料:
  • 我只想用下面的公式从任何给定的数字创建一个因子列表。我不允许使用列表,因此,我模仿使用字符串如下: 例如,假设我们选择num=12:

  • 我正在学习Java,有一个非常简单的要求,我似乎不知道哪里出了问题。一个简单的ArrayList,用于写入控制台 名字 姓 多布 我似乎不知道我怎么能把它们打印在一行里 名字姓多布 另一个名字另一个姓氏另一个Dob 提前感谢你所有的帮助。

  • 问题内容: 我有以以下格式(示例)保存的数据(数字): 是否有任何python-way方法来排列数字并将其作为 (我无法预测列的大小)。 问题答案: 这是一个简单的独立示例,显示了如何设置可变列宽的格式: 输出:

  • 标准输出 1.gossh远程执行命令返回格式. #批量模式首行首先打印所有的远程机器IP. [servers]=[192.168.56.2 192.168.56.2] #机器ip ip=xxx.xxx.56.2 #远程执行命令 command=uname #命令执行完后的退出值,就是$? return=0 #远程执行命令输出到标准输出和错误输出的结果 Linux ##换行和---分隔线 ---

  • 利用call函数控制数组的输出格式: #include <stdio.h> int matrix[10][10]; /* 格式化输出数组 */ void print(int matrix[][10], int m, int n) { int i, j; for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j)

  • 希望有人能帮我做这件事,我对Java很在行。我的问题是,当我打印数组时,会得到一些字符,我想打印数组中的点数。(请忽略不相关的代码,我甚至还没有完成)