Python Exercises: Insert space before capital letters in word
Python String: Exercise-110 with Solution
Write a Python program to insert space before every capital letter appears in a given word.
Sample Data:
("PythonExercises") -> "Python Exercises"
("Python") -> "Python"
(“PythonExercisesPracticeSolution”) -> “Python Exercises Practice Solution”
Sample Solution:
Python Code:
def test(word):
result = ""
for i in word:
if i.isupper():
result=result+" "+i.upper()
else:
result=result+i
return result[1:]
word = "PythonExercises"
print("Original Word:", word)
print("Insert space before capital letters in the said word:")
print(test(word))
word = "Python"
print("Original Word:", word)
print("Insert space before capital letters in the said word:")
print(test(word))
word = "PythonExercisesPracticeSolution"
print("Original Word:", word)
print("Insert space before capital letters in the said word:")
print(test(word))
Sample Output:
Original Word: PythonExercises Insert space before capital letters in the said word: Python Exercises Original Word: Python Insert space before capital letters in the said word: Python Original Word: PythonExercisesPracticeSolution Insert space before capital letters in the said word: Python Exercises Practice Solution
Flowchart:

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 Python Exercise: Count the number of leap years within the range.
Next Python Exercise: Alphabet position in a string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Python: Tips of the Day
Print Current Directory:
import os print(os.getcwd())
/tmp/sessions/74e2393fba512543
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook