Negative indexing of python tuples and indexing range.pptx

AsimMukhtarCheema1 5 views 5 slides Aug 20, 2024
Slide 1
Slide 1 of 5
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5

About This Presentation

Explore the power of negative indexing in Python tuples with this comprehensive slide deck! Discover how negative indexing can simplify tuple access and manipulation, and learn practical examples that showcase its utility in real-world scenarios. Perfect for both beginners and experienced Python dev...


Slide Content

Negative indexing and range of indexes

Negative indexing: Negative indexing means start from the end. -1 refers to the last item, -2 refers to the second last item etc. The first item has index 0.

Example: thistuple = ("apple", "banana", "cherry") print(thistuple[-1])

Range of indexes You can specify a range of indexes by specifying where to start and where to end the range. When specifying a range, the return value will be a new tuple with the specified items.

Example thistuple = ( "apple" , "banana" , "cherry" , "orange" , "kiwi" , "melon" , "mango" ) print (thistuple[ 2 : 5 ])