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:
0
.name[0:7]
includes characters from index 0 to 6 (7 is excluded).name[1]
gives the second character of the string.🧠 Learning: Python’s string slicing uses the format string[start:end]
It includes the start index but excludes the end index.
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:
1
is the last character, 2
is second last, and so on.name[-10:-1]
is same as name[0:9]
→ This is helpful for reverse-style slicing.[:4]
→ from start till index 3[3:]
→ from index 3 to end