How to make strings upper case in python

Question:

I have been looking around for an answer to this and what I could find was you use the .upper() command but this doesn’t seem to work,

Example,

 >>> x = a
 >>>x.upper()
 >>>print (x)

But what it displays is just the original.

Asked By: Ieuan Franssens

||

Answers:

The correct way to do it is

x = x.upper()

Python strings are immutable, so str.upper() returns the result instead of changing the string in place (as do all other string manipulation functions).

Answered By: NPE

x.upper() does not modify x; it just computes the new string, which you’d see if you printed x.upper(). To retain that value, you could assign it back to x.

Answered By: Scott Hunter
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.