Page 1 of 1

Python: Slicing

Posted: Sat Oct 25, 2025 4:16 am
by The Jason

Code: Select all

website_name = "Hosting Chatter"

print(website_name[ : ])

# Will print the whole string starting with index 0 which is the letter H.

print(website_name[0]

# Will print index 0 which is element 1 which is the letter "H".

print(website_name[1: ]

# Will print index 1 which is element 2 which is "o". and then the rest of the string.

Code: Select all

band_name = "The Zombies"

print(band_name[3:5])

# Will print the letters: "Z" (index 3, element 4), "o" (index 4, element 5), but NOT (index 5, element 6)

print(band_name[ :7])

# Will print all letters up to but not including the letter "i" (index 7, element 8).