How to capitalize a string in Python? [duplicate]
问题 This question already has answers here : How to change a string into uppercase (6 answers) Closed last year . How can I convert a string to all capitals in Python 3.4? for example, I want to convert: string to: STRING I have tried with the .upper method, but it returns: "string".upper <built-in method upper of str object at 0x0283E860> How can I fix this problem? 回答1: You can use string.upper() method in Python 3.4 For example >>> x = 'abcdef' >>> x.upper() >>> 'ABCDEF' Or if you only need