10

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?

double-beep
  • 5,031
  • 17
  • 33
  • 41
A..
  • 375
  • 2
  • 6
  • 15

2 Answers2

16

You can use string.upper() method in Python 3.4

For example

>>> x = 'abcdef'
>>> x.upper()
>>> 'ABCDEF'

Or if you only need the first letter to be capitalized, you can use string.capitalize() method like

>>> x = 'abcdef'
>>> x.capitalize()
>>> 'Abcdef'

Hope it helps.

Eric
  • 2,636
  • 21
  • 25
1

You're just missing the parentheses since upper is a method. It should be "string".upper(). If you don't add the parentheses, it will return the function object instead of calling the function.

Arkane
  • 352
  • 4
  • 10