Master Python Strings
Learn how to slice text and find lengths like a pro. Coding made simple for everyone!
What is String Slicing?
Think of a string as a row of lockers. Each character has a number (an index). Slicing is just grabbing a specific range of those lockers. We use the [start:end] format to do this.
The Basics
- • Start index: Where you begin (included).
- • End index: Where you stop (excluded).
- • Negative indexing: Counting from the back!
The len() Function
Need to know how many characters are in a word? Just use len("hello"). It returns the total count instantly!
Pro Tip
text = "Python"
print(text[0:2]) # Outputs: Py