How to change a string into uppercase

gadss picture gadss · Feb 13, 2012 · Viewed 1.2M times · Source

I have problem in changing a string into uppercase with Python. In my research, I got string.ascii_uppercase but it doesn't work.

The following code:

 >>s = 'sdsd'
 >>s.ascii_uppercase

Gives this error message:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'str' object has no attribute 'ascii_uppercase'

My question is: how can I convert a string into uppercase in Python?

Answer

Dan D. picture Dan D. · Feb 13, 2012
>>> s = 'sdsd'
>>> s.upper()
'SDSD'

See String Methods.