Python – Access Tuple Items
1. What Does โAccess Tuple Itemsโ Mean?
Accessing tuple items means getting values from a tuple.
Tuples are like lists, but:
๐ Tuples cannot be changed.
2. Access Items Using Index
Each item in a tuple has a position number (index).
Important:
-
Index starts from 0
Example
Output:
3. Negative Indexing
Negative index starts from the end.
-
-1โ last item -
-2โ second last item
Example
Output:
4. Access a Range of Items (Slicing)
You can get more than one item using slicing.
Example
Output:
๐ End index is not included.
5. Access From Beginning
Example
Output:
6. Access Till End
Example
Output:
7. Access Items Using Loop
Example
8. Check if Item Exists
Example
9. Tuple Length
Example
10. Common Beginner Mistakes
โ Index Out of Range
โ Error.
โ Fix:
โ Trying to Change Tuple Item
โ Error: tuple items cannot be changed.
11. Simple Practice Examples
Example 1: Print First and Last Item
Example 2: Slice Tuple
Example 3: Check Name
12. Summary (Access Tuple Items)
โ Use index to access items
โ Index starts from 0
โ Negative index works
โ Slicing returns a tuple
โ Tuples are read-only
๐ Perfect for Beginner eBook
This chapter is ideal for:
-
Python beginner books
-
School & college students
-
Self-learners
If you want next, I can write:
-
Change Tuple Items
-
Add Tuple Items
-
Remove Tuple Items
-
Tuple Exercises
Just tell me ๐
