格式化能干嘛

楼主: 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