Python: Slicing - # 2

Post Reply
User avatar
Jason
Site Admin
Posts: 853
Joined: Tue Jul 01, 2025 10:13 am

Code: Select all

band_name = "Shocking Blue"

print(band_name[ : : 2])

# Going thru the whole string and skipping every letter so outputting the letters: "S", "o", "k", "n", "B", and "u"

band_name = "The Monkees"

print(band__name[2 : 7 : 3])

# Starting at index 2 which is "e", skipping every 2nd letter until the index 7 which is also "e", so that "n" is displayed.


 

POSTREACT(ions) SUMMARY

Post Reply