Chapter 3: Strings in Python – Theory Notes


Introduction to Strings

name = "Prathamesh"
nameshort = name[0:7]
print("The short version of my name is", nameshort)

character1 = name[1]
print("The second letter of my name is", character1)

📚 Key Concepts:

🧠 Learning: Python’s string slicing uses the format string[start:end]

It includes the start index but excludes the end index.


🔁 Negative Indexing

name = "Prathamesh"
print(name[-10:-1])  # Output: rathames
print(name[0:9])     # Output: Prathames

print(name[:4])      # Same as name[0:4] -> "Prat"
print(name[1:])      # Same as name[1:10] -> "rathamesh"
print(name[3:])      # Same as name[3:10] -> "thamesh"

📚 Key Concepts:


🪜 Slicing with Skip Values