Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Convert a String to Uppercase or Lowercase

Python Convert a String to Uppercase or Lowercase

Document Object Reference Manual Python3 Examples

In Python, you can use the upper() and lower() method to convert a string to uppercase or lowercase.upper() The method converts all characters in the string to uppercase, while the lower() method converts all characters in the string to lowercase.

Example

Raw strings

original_string

=

"Hello, World!"

Convert to uppercase

upper_case_string

=

original_string.

upper

(

)

Convert to lowercase

lower_case_string

=

original_string.

lower

(

)

Output result

print

(

"Original String:"

,

original_string

)

print

(

"Upper Case String:"

,

upper_case_string

)

print

(

"Lower Case String:"

,

lower_case_string

)

Code analysis:

Output result:

Original String: Hello, World!
Upper Case String: HELLO, WORLD!
Lower Case String: hello, world!

Document Object Reference Manual Python3 Examples