HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonCriticalCanonical

How to change a string into uppercase?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howuppercasechangestringinto

Problem

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 "", line 1, in 
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.

Code Snippets

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

Context

Stack Overflow Q#9257094, score: 1343

Revisions (0)

No revisions yet.