Print Each Character
Print every character of entered text on its own line with Python. Students iterate directly over a string and see how spaces and empty input affect output.
1# Take string input2s = input("Enter a string: ")34# Print each character5for char in s:6 print(char)
Output
Enter a string: Hello H e l l o
In this one
- Iterate text directly
- Use print's newline
- Include spaces as characters
How it works
- 1
Read s.
- 2
Visit each character in input order.
- 3
Print each on its own line.
Edge cases
Does a space get skipped?
Does a space get skipped?
No. It is printed as a character.
How many lines for abc?
How many lines for abc?
Three.
What's going on
A for loop supplies one character at a time without numeric indexes. print uses its default newline after every supplied value.
For cat, the output has three character lines. An ordinary space produces a line containing that space, which may look blank. Empty input has no characters, so the loop prints nothing; no final extra print is present.
Does a space get skipped? No. It is printed as a character.
How many lines for abc? Three.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Does this require indexing?
Pick an answer to check it.
Question 2
Does a space get skipped?
Pick an answer to check it.
Questions people ask
Does a space get skipped?
No. It is printed as a character.
How many lines for abc?
Three.
Does this require indexing?
No, direct iteration supplies characters.
๐Related Content
- ๐
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- ๐
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- ๐ป
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum