【发布时间】:2020-12-11 16:13:46
【问题描述】:
我有 12 个不同的字符串,我想要一个元组格式,因为我稍后会在图表中使用这些字符串。 如何将相同的字符串添加到字符串数组中?
我有这几个月: 一月、二月等,我想在每个字符串中插入“一月 LSDS”、“二月 LSDS”等。
我试过了,但我得到一个错误:
insert = 'LSDS'
month_names = ('January {}', 'February {}','March {}','April {}', 'May {}', 'June {}', 'July {}', 'August {}', 'September {}', 'October {}', 'November {}', 'December {}').format(insert)
print(month_names)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-167-c79c038f3ebc> in <module>
3 insert = 'LSDS'
4
----> 5 month_names = ('January {}', 'February {}','March {}','April {}', 'May {}', 'June {}', 'July {}', 'August {}', 'September {}', 'October {}', 'November {}', 'December {}').format(insert)
6
7 print(month_names)
AttributeError: 'tuple' object has no attribute 'format'
【问题讨论】:
标签: python string numpy jupyter