DEV Community

Kelvin Wangonya
Kelvin Wangonya

Posted on • Originally published at wangonya.com on

3 1

A quick reference to Python string methods - Cases

Cases

capitalize()

Parameters

string.capitalize()
Enter fullscreen mode Exit fullscreen mode

capitalize() takes no parameters.

Return value

Returns a copy of the string with the first letter of the first word capitalized and all the other characters of thestring in lowercase.

Example

Python 3.7.4

>>> s = "soMe peopLe AcTUally tyPE Like thIs."

>>> s.capitalize()
'Some people actually type like this.'
Enter fullscreen mode Exit fullscreen mode

title()

Parameters

string.title()
Enter fullscreen mode Exit fullscreen mode

title() takes no parameters.

Return value

Returns a copy of the string with the first letter of each word capitalized and all the other characters of thestring in lowercase.

Example

Python 3.7.4

>>> s = "soMe peopLe AcTUally tyPE Like thIs."

>>> s.title()
'Some People Actually Type Like This.'
Enter fullscreen mode Exit fullscreen mode

swapcase()

Parameters

string.swapcase()
Enter fullscreen mode Exit fullscreen mode

swapcase() takes no parameters.

Return value

Returns a copy of the string with all uppercase characters swapped to lowercase and lowercasecharacters swapped to uppercase.

Example

Python 3.7.4

>>> s = "soMe peopLe AcTUally tyPE Like thIs."

>>> s.swapcase()
'SOmE PEOPlE aCtuALLY TYpe lIKE THiS.'
Enter fullscreen mode Exit fullscreen mode

upper()

Parameters

string.upper()
Enter fullscreen mode Exit fullscreen mode

upper() takes no parameters.

Return value

Returns a copy of the string with all characters in uppercase.

Example

Python 3.7.4

>>> s = "soMe peopLe AcTUally tyPE Like thIs."

>>> s.upper()
'SOME PEOPLE ACTUALLY TYPE LIKE THIS.'
Enter fullscreen mode Exit fullscreen mode

lower()

Parameters

string.lower()
Enter fullscreen mode Exit fullscreen mode

lower() takes no parameters.

Return value

Returns a copy of the string with all characters in lowercase.

Example

Python 3.7.4

>>> s = "soMe peopLe AcTUally tyPE Like thIs."

>>> s.lower()
'some people actually type like this.'
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay