標題說明了一切。我有一個包含一些值的串列,我想列印它們以便括號不顯示。我知道我可以使用 print(*value) 但這在使用 f 字串時不起作用。為了說明我的觀點:
print(f'This list contains: {function_that_returns_list()}')
我一直在尋找幾個小時的答案,因此非常感謝任何幫助。
uj5u.com熱心網友回復:
嘗試這個:
print(f'This list contains: {" ".join(function_that_returns_list())}')
uj5u.com熱心網友回復:
為什么不砍掉結果中的第一個和最后一個字符str,代表開始和結束括號?下面的簡要示例:
L = ['1', '2', '3']
print(f'This list contains: {str(L)[1:-1]}')
出去:
This list contains: '1', '2', '3'
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/361622.html
標籤:Python
