Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Case Conversion

Give Feedback

In this lesson, you’ll explore string methods that perform case conversion on the target string. These are the case conversion methods:

  • str.capitalize()
  • str.lower()
  • str.swapcase()
  • str.title()
  • str.upper()

Here’s how to use str.capitalize():

>>>
>>> s = 'egG BacOn SauSAGE loBSter'
>>> s.capitalize()
'Egg bacon sausage lobster'

>>> s = 'egg123#BACON#.'
>>> s.capitalize()
'Egg123#bacon#.'

Here’s how to use str.lower():

>>>
>>> s = 'EGG Bacon 123 sAusAge lOBSTEr.'
>>> s.lower()
'egg bacon 123 sausage lobster.'

Here’s how to use str.swapcase():

>>>
>>> s = 'eGG Bacon 123 sausage LOBSTER.'
>>> s.swapcase()
'Egg bACON 123 SAUSAGE lobster.'

Here’s how to use str.title():

>>>
>>> s = 'the sun also rises'
>>> s.title()
'The Sun Also Rises'

>>> s = "what's happened to ted's IBM stock?"
>>> s.title
"What'S Happened To Ted'S Ibm Stock?"

Here’s how to use str.upper():

>>>
>>> s = 'EGG Bacon 123 sauSAGE lOBsTer.'
>>> s.upper()
'EGG BACON 123 SAUSAGE LOBSTER.'

Become a Member to join the conversation.