Python Practice › Loop Programs › Program 3
Build a string character by character
Write a Python program that adds each character of a word from the user to an empty string.
Input
python
Output
Enter a word: python python
Approach
- Start with an empty string and append each character with
+=.
Solution
word = input("Enter a word: ")result = ""for ch in word: result += chprint(result)Outputtyped input: python
Enter a word: python python
Line by line
Line 2
The empty string is the starting value.
Lines 3-4
Each loop pass appends one character.
Learn the concept
New to this topic? Read the lesson, then come back.