Remove First Character
Remove the first character of text with slicing. Students guard empty input, retain the remaining sequence, and see why a one-character result becomes empty.
1# Take string input2s = input("Enter a string: ")34# Remove first character5if len(s) > 0:6 result = s[1:]7 print(f"After removal: {result}")8else:9 print("String is empty")
Output
Enter a string: Hello After removal: ello
In this one
- Exclude the first position
- Use an open-ended slice
- Handle one-character text
How it works
- 1
Check s is nonempty.
- 2
Create s[1:] as result.
- 3
Print it or the empty-input message.
Edge cases
What if s has one character?
What if s has one character?
The result is empty.
What if s is already empty?
What if s is already empty?
The code prints String is empty.
What's going on
s[1:] starts at index one and continues to the end. It therefore omits the original index-zero character.
The source string is unchanged; result holds the shortened text. For cat, result is at. A one-character input leaves an empty result, which is valid. The explicit empty branch gives feedback rather than displaying an apparently blank transformation.
What if s has one character? The result is empty.
What if s is already empty? The code prints String is empty.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which slice removes the first character?
Pick an answer to check it.
Question 2
What if s has one character?
Pick an answer to check it.
Questions people ask
What if s has one character?
The result is empty.
What if s is already empty?
The code prints String is empty.
Which slice removes the first character?
s[1:].
๐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