w3resource
Python Exercises

Python: Split a string at uppercase letters

Python Regular Expression: Exercise-43 with Solution

Write a Python program to split a string at uppercase letters.

Sample Solution:-

Python Code:

import re
text = "PythonTutorialAndExercises"
print(re.findall('[A-Z][^A-Z]*', text))

Sample Output:

['Python', 'Tutorial', 'And', 'Exercises']

Flowchart:

Flowchart: Regular Expression - Split a string at uppercase letters.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to find urls in a string.
Next: Write a Python program to do a case-insensitive string replacement.

What is the difficulty level of this exercise?