Add Characters Between Each Character
Insert a separator between string characters with join. Students treat a string as an iterable of characters and avoid adding separators at either endpoint.
1# Take string input2s = input("Enter a string: ")3char = input("Enter character to add: ")45# Add between characters6result = char.join(s)7print(f"Result: {result}")
Output
Enter a string: Hello Enter character to add: - Result: H-e-l-l-o
In this one
- Use a separator as receiver
- Join an iterable of characters
- Avoid endpoint separators
How it works
- 1
Read the source and separator.
- 2
Call char.join(s).
- 3
Print the joined character sequence.
Edge cases
What happens for one character?
What happens for one character?
It is returned without a separator.
What happens for empty s?
What happens for empty s?
The result is empty.
What's going on
char.join(s) places the separator between consecutive characters. The separator is the method's receiver; the text to join is its argument.
For abc and separator -, the result is a-b-c. No extra separator appears before a or after c. The separator response can itself contain multiple characters. Empty and one-character strings naturally contain no character gaps to fill.
What happens for one character? It is returned without a separator.
What happens for empty s? The result is empty.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Where does join insert separators?
Pick an answer to check it.
Question 2
What happens for one character?
Pick an answer to check it.
Questions people ask
What happens for one character?
It is returned without a separator.
What happens for empty s?
The result is empty.
Where does join insert separators?
Between elements only.
๐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