-2

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.

fredtantini
  • 15,966
  • 8
  • 49
  • 55

2 Answers2

0

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).

NPE
  • 486,780
  • 108
  • 951
  • 1,012
0

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.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101