python格式化字元

來源:互聯網
上載者:User

標籤:bsp   格式化   輸出   body   比例   注意   print   顯示   code   

格式化字元 含義
%s 字串
%d 有符號十進位整數,%010d表示輸出的整數不足位元時,前面用0來填充
%f 浮點數,%.02f(%.2f)表示只顯示小數後的兩位內容
%% 輸出%
name = ‘小明‘num = 123456price = 5.0weight = 9.0money = price * weightscale = 0.25print("我的名字叫%s,請多多關照!"%name)print("我的學號是%09d"%num)print("蘋果的單價是%.02f,重量是%.02f,總價格是%.02f"%(price,weight,money))print("輸出比例為%.2f%%"%(scale*100))print("%")print("%s的成績在班上是前10%%"%name)

輸出結果如下:(注意區別後三條代碼)

我的名字叫小明,請多多關照!我的學號是000123456蘋果的單價是5.00,重量是9.00,總價格是45.00輸出比例為25.00%%小明的成績在班上是前10%

 

python格式化字元

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.