Affiliate link
Python - Strings Formatting
Python provides these built-in functions that you can use on strings for formatting.
pystring = 'a Python string.'String - Case
| Function | Description | Example | Result |
|---|---|---|---|
capitalize | Capitalize first character | pystring.capitalize() | A Python string. |
title | Capitalize all the words | pystring.title() | A Python String. |
upper | Convert string to uppercase | pystring.upper() | A PYTHON STRING. |
lower | Convert string to lowercase | pystring.lower() | a python string. |
swapcase | Swap uppercase to lowercase and lowercase to uppercase. | pystring.swapcase() | A pYTHON STRING. |
String - Alignment
| Function | Description | Example | Result |
|---|---|---|---|
center | Center the string within the number of space defined | pystring.center(30) | " a Python string. " |
ljust | Left justify with the number of space | pystring.ljust(30) | "a Python string. " |
rjust | Right justify with the number of space | pystring.rjust(30) | " a Python string." |
Affiliate link
Affiliate link





