Converting Strings to UPPERCASE ?

Dave Cook daverz at mindspring.com
Mon Sep 17 23:42:25 EDT 2001


On Tue, 18 Sep 2001 13:15:58 +1000, Peter Moscatt <pmoscatt at iprimus.com.au>
wrote:

>I am having difficulty in converting a string to Upercase - how is this best
>achieved ??

You can use the string.upper function.  There is also string.lower,
string.swapcase, string.capitalize, and string.capwords.  I had worked out
how to do it with string.translate before I remembered that.

  import string
  trans = string.maketrans(string.lowercase, string.uppercase)
  s = ("the quick red fox jumped over the lazy brown dog.")
  t = string.translate(s, trans)
  print t

Dave cook



More information about the Python-list mailing list