python - 在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',
...]
解决方案
推荐阅读
- c# - 如何将对象转换为通用?
- haskell - 模式匹配字段,但也有一个代表整个数据类型的变量
- java - 如何从 inputreader.read() 中读取数据?
- c# - 如何在不同 DbContext 上找到的模型之间创建关系?
- codesniffer - 包括排除规则
- php - 如何根据用户输入从数据库中获取数据并在 php 中使用异步 POST 显示为 JSON 数组
- typescript - 如何在 rxjs 6 中将“静态”可观察与“动态”合并?
- node.js - Azure Node.js 简易 API 中间件
- java - Tomcat 9 中的 POST 请求禁止 Spring Boot 403
- python - 从多个 csv 文件创建 2D 矩阵