21
Phase 5 - Category 1: Basic String Handling
Chapter 21 • Beginner
60 min
Phase 5 - Category 1: Basic String Handling
Introduction to Strings
Strings are sequences of characters. In Python, strings are immutable, meaning you can't change them directly - you create new strings.
String Basics
Creating Strings
python.js
s = "Hello"
s = 'World'
s = """Multi-line string"""
String Operations
len(s)- length of strings[i]- character at index is + t- concatenations * n- repeat string n times
String Methods
s.upper()- convert to uppercases.lower()- convert to lowercases.strip()- remove whitespace
Key Concepts
- Indexing: Access characters by position (0-based)
- Immutability: Strings can't be modified in place
- Slicing: Extract substrings using [start:end]
- Iteration: Loop through characters
Common Patterns
- Get string length
- Access first and last character
- Convert case
- Concatenate strings
- Compare strings lexicographically
Hands-on Examples
String Length
# Take string input
s = input("Enter a string: ")
# Get length
length = len(s)
print(f"Length: {length}")Use len() function to get the number of characters in the string.
Related Tutorials
🔗Related Content
- 💻
Phase 5 - Practice Problems
Practice Phase 5 concepts with hands-on coding problems
- 📝
Phase 5 - Quiz
Test your Phase 5 understanding with assessment questions
- ➡️
Phase 6 - Get Started
Continue to Phase 6 after mastering Phase 5
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum