golang – fmt 格式化參數

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

原文

基本

%vthe value in a default formatwhen printing structs, the plus flag (%+v) adds field names%#va Go-syntax representation of the value%Ta Go-syntax representation of the type of the value%%a literal percent sign; consumes no value

 

The default format for %v is:

bool:                    %tint, int8 etc.:          %duint, uint8 etc.:        %d, %#x if printed with %#vfloat32, complex64, etc: %gstring:                  %schan:                    %ppointer:                 %p

 

Boolean:

%tthe word true or false

Integer:

%bbase 2%cthe character represented by the corresponding Unicode code point%dbase 10%obase 8%qa single-quoted character literal safely escaped with Go syntax.%xbase 16, with lower-case letters for a-f%Xbase 16, with upper-case letters for A-F%UUnicode format: U+1234; same as "U+%04X"

Floating-point and complex constituents:

%bdecimalless scientific notation with exponent a power of two,in the manner of strconv.FormatFloat with the 'b' format,e.g. -123456p-78%escientific notation, e.g. -1.234456e+78%Escientific notation, e.g. -1.234456E+78%fdecimal point but no exponent, e.g. 123.456%Fsynonym for %f%g%e for large exponents, %f otherwise%G%E for large exponents, %F otherwise

String and slice of bytes (treated equivalently with these verbs):

%sthe uninterpreted bytes of the string or slice%qa double-quoted string safely escaped with Go syntax%xbase 16, lower-case, two characters per byte%Xbase 16, upper-case, two characters per byte

Pointer:

%pbase 16 notation, with leading 0x

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.