首页 > 解决方案 > 在python中的格式化方法中使用大写方法

问题描述

string_ = "hello world"
print("{0[1].capitalize()} {0[0].capitalize()}".format(string_.split(" ")))

运行这个我得到

AttributeError: 'str' object has no attribute 'capitalize()'

请告诉我出了什么问题,因为字符串方法中有大写方法!

dir(string_)
Out[108]: 
[...
 'capitalize',
 ...]

标签: pythonformattingpython-3.8capitalize

解决方案


推荐阅读