【发布时间】:2026-02-14 18:00:01
【问题描述】:
我正在尝试使用 Python 从数组循环到带有占位符的文本块。但是我不知道如何在前一个文本块下附加或加入文本块。
如何将数组循环到带有占位符的文本块中,然后将各个文本块相互叠加输出。
我的数组看起来像:
[{'name': James, 'age': 40},{'name': Frank, 'age': 29}]
我的占位符模板:
f'''
Profile -
Name: {name}
Age: {age}
'''
我正在尝试输出
Profile -
Name: James
Age: 40
Profile -
Name: Frank
Age: 28
我尝试过同时使用连接和连接 - 无济于事,即:
textBlock = ""
for i in data:
text = f'''Name: {i{'name']}<br>Age: {i{'age']}<br>'''
textBlock.join(text)
【问题讨论】:
标签: python arrays python-3.x