格式化能幹嘛

作者: corydoras09 (一劍籙魂)   2021-05-16 12:34:03
那個
看不懂格式化
是幹嘛用的
範例這樣寫
>>>thing='wereduck'
>>>place='werepond'
>>>f'The {thing} is in the {place}'
'The wereduck is in the werepond'
那幹嘛不一開始就打好==
就只是塞字進去嗎?
好複雜
還有什麼
{thing.capatalize()}
{thing:>20}
f'{thing[-4:]=}

怎麼這麼複雜
作者: lturtsamuel (港都都教授)   2020-05-16 12:34:00
那不叫格式化==
作者: corydoras09 (一劍籙魂)   2021-05-16 12:35:00
python的書:(後面的題目我一個都看不懂,https://i.imgur.com/GTAbfhs.jpghttps://i.imgur.com/PbuhTko.jpg
作者: lturtsamuel (港都都教授)   2021-05-16 12:38:00
講簡單的 因為你不能在寫程式的時候預測程式執行時要印什麼東西出來 例如你寫了一隻載a片的程式 想顯示下載的進度 你就不能預先寫死25% 50% 需要執行的時候算
作者: corydoras09 (一劍籙魂)   2021-05-16 12:39:00
懂了,大師
作者: Apache (阿帕契)   2021-05-16 13:34:00
string format沒錯啊 C就是這樣命名了

Links booklink

Contact Us: admin [ a t ] ucptt.com