Sling Academy
Home/Python/Python: Converting a string to lowercase/uppercase

Python: Converting a string to lowercase/uppercase

Last updated: May 25, 2023

In Python, you can use the str.lower() and str.upper() methods to change the case of all characters in a string to lowercase or uppercase, respectively. These methods have been part of the programming language for almost two decades. They are still widely used today.

Converting to lowercase using the lower() method

Example:

my_string = "Welcome to Sling Academy!"
lowercase_string = my_string.lower()
print(lowercase_string)

Output:

welcome to sling academy!

Converting to uppercase using the upper() method

Example:

my_string = "Some greate RPG games are Witcher 3, Elden Ring, Cyberpunk 2077, and God of War."
uppercase_string = my_string.upper()
print(uppercase_string)

Output:

SOME GREATE RPG GAMES ARE WITCHER 3, ELDEN RING, CYBERPUNK 2077, AND GOD OF WAR.

Next Article: Python: 4 Ways to Convert a String into a List

Previous Article: Python: 8 Ways to Concatenate Strings

Series: Working with Strings in Python

Python

You May Also Like

  • Python Warning: Secure coding is not enabled for restorable state
  • Python TypeError: write() argument must be str, not bytes
  • 4 ways to install Python modules on Windows without admin rights
  • Python TypeError: object of type ‘NoneType’ has no len()
  • Python: How to access command-line arguments (3 approaches)
  • Understanding ‘Never’ type in Python 3.11+ (5 examples)
  • Python: 3 Ways to Retrieve City/Country from IP Address
  • Using Type Aliases in Python: A Practical Guide (with Examples)
  • Python: Defining distinct types using NewType class
  • Using Optional Type in Python (explained with examples)
  • Python: How to Override Methods in Classes
  • Python: Define Generic Types for Lists of Nested Dictionaries
  • Python: Defining type for a list that can contain both numbers and strings
  • Using TypeGuard in Python (Python 3.10+)
  • Python: Using ‘NoReturn’ type with functions
  • Type Casting in Python: The Ultimate Guide (with Examples)
  • Python: Using type hints with class methods and properties
  • Python: Typing a function with default parameters
  • Python: Typing a function that can return multiple types