iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 7
0
Data Technology

Python學習筆記系列 第 7

[ Day7 ] 格式化輸出

  • 分享至 

  • twitterImage
  •  

Strings

  • 使用str()將字串輸出

Floating Point Numbers

  • 浮點數使用%n1.n2的格式,n1表示該字串必須包含至少幾個數字(若沒足額的數字則用空白填滿位子,n2表示小數點後的值面擷取至幾位

https://ithelp.ithome.com.tw/upload/images/20171210/20107290WsLWb9NMyI.jpg

Conversion Format methods

  • 格式化成字串: %s和%r將任何python物件以2種方式str()和repr()方式轉換成字串
    使用string.format()函式
    運用格式化的方式將你的物件轉換成字串,語法如下

'String here {var1} then also {var2}'.format(var1='something1',var2='something2')

https://ithelp.ithome.com.tw/upload/images/20171210/20107290TYU0MaCC0V.jpg

更多補充:
%d 以10 進位整數方式輸出
%e, %E 將浮點 數以10進位方式輸出,並使用科學記號
%o 以8進 位整數方式輸出
%x, %X 將整 數以16進位方式輸出
%c 以字元 方式輸出

其實每次都想多發一些文,不過這周一到日白天到下午都要上大數據的課程和討論期末專題報告,還請各位讀者諒解~

參考資料來源: Go from zero to hero in Python


上一篇
[ Day6 ] Strings 字串介紹
下一篇
[Day 8] Lists 串列
系列文
Python學習筆記14
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言