Skip to main content

Modifying Strings in Python

Strings in Python come with many built-in methods ready for you to use.


Upper Case

Example

Prompt
Demonstrate Python upper case.
Output: complete Python program

Lower Case

Example

Prompt
Demonstrate Python lower case.
Output: complete Python program

Remove Whitespace

Whitespace means any spaces sitting before and/or after the real text. You will often want to get rid of them.

Example

Prompt
Demonstrate Python remove whitespace.
Output: complete Python program

Replace String

Example

Prompt
Demonstrate Python replace string.
Output: complete Python program

Split String

The split() method cuts a string at the separator you give it and returns the pieces as a list.

Example

Prompt
Demonstrate Python split string.
Output: complete Python program