Search code examples
pythonstringfunctionuppercasestring-conversion

How to change a string into uppercase?


How can I convert a string into uppercase in Python?

When I tried to research the problem, I found something about string.ascii_uppercase, but it couldn't solve the problem:

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

See How do I lowercase a string in Python? for the opposite.


Solution

  • Use str.upper():

    >>> s = 'sdsd'
    >>> s.upper()
    'SDSD'
    

    See String Methods.