OneBite.Dev - Coding blog in a bite size

convert a string to uppercase in python

Code snippet on how to convert a string to uppercase in python

  myStr = "this is a string"
  newStr = myStr.upper()
  print(newStr)

The code above provides a simple example of how to convert a string to uppercase in Python.

The first line assigns the string “this is a string” to the variable myStr.

The second line calls the upper() method on the myStr variable, and assigns the result to the newStr variable. The upper() method converts the string to uppercase.

The last line prints the newStr variable, which will display the string in uppercase. In this example the output would be “THIS IS A STRING”.

python