我在使用 Python 将字符串更改为大写时遇到问题。在我的研究中,我得到了 string.ascii_uppercase
但它不起作用。
以下代码:
>>s = 'sdsd'
>>s.ascii_uppercase
给出此错误消息:
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'str' object has no attribute 'ascii_uppercase'
我的问题是: 如何在 Python 中将字符串转换为大写字母?
原文由 gadss 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用
str.upper()
:请参阅 字符串方法。