是否可以在 fstrings 中添加 if 語句,例如:id1='somestring'for row,col in <some_condition>: col.to_excel(f'{id1}_concat(0,row[0]))我想用零填充單個數字 row[0] ,如果 row[0] 不是單個數字,則不應用填充,謝謝!
1 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
IIUC,您想使用格式規范迷你語言來使用字符串格式。
ls = [1,2,10,20,3,4,30,40]
for i in ls:
? ? print(f'{i:02d}')
輸出:
01
02
10
20
03
04
30
40
添加回答
舉報
0/150
提交
取消