看板 Python 關於我們 聯絡資訊
code : for i in range(1, 5): s = "{0:>" + str(i) + "}" print(i, s, s.format("*") ) output : 1 {0:>1} * 2 {0:>2} * 3 {0:>3} * 4 {0:>4} * 問題 '*'前為何會有空白一直增加 網路上查到format的用法都是 像printf來格式化自己要的排版 上例中直接把字串format後面給符號不太清楚是什麼意思 希望有人能幫我解惑一下 另外 問一個vim的小問題 我用set noai來取消貼上自動縮排好像沒有 不知道為何 所以改用r!cat 然後貼上內容再ctrl+D就行了 但是r!cat是什麼意思呢 !後面加指令 來cat等待輸入我應該知道 但是r是我就不清楚了 以上,謝謝大家。 -- Talk is cheap. Show me the code. - Torvalds, Linus (2000-08-25). -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.67.180.162 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1500812462.A.B84.html
ptt0720: python那部分好像是對齊的意思 向右對齊1 2 3 4 打擾了XD 07/23 20:35
zerof: https://pyformat.info/ 07/23 20:37
s860134: 一定是官方文件寫太爛導致你看不懂 07/23 20:52
ptt0720: http://imgur.com/sMU99mK 07/23 20:57
ptt0720: 我重新實驗一次 發現我明明用9格對齊 *印完還是給我一個 07/23 20:58
ptt0720: 空格,好像不太對 07/23 20:59
TaiwanFight: 因為你用print,如: print('*','*') 不同 print('**') 07/23 21:43
TaiwanFight: 簡單點: print('{:^9}{}'.format('*'*i,'|')) 07/23 21:44
darkgerm: 回答你vim問題,r 是 read 的縮寫,會把後面的結果 07/25 22:13
darkgerm: 讀進 buffer 中,與之相反的指令是 w[rite] 07/25 22:14