Last answered:

25 Jul 2023

Posted on:

21 Jul 2023

0

Resolved: Can you please provide some examples of using the range methods?

Like get_item, reversed etc.


1 answers ( 1 marked as helpful)
Instructor
Posted on:

25 Jul 2023

1

Hi Panagiotis!
Thanks for reaching out.

An example for the reversed() method:

my_list = [1, 5, 10, 2]
for n in reversed(my_list):
    print(n)

An example for the getitem() method:

class MyList:
    def __init__(self, data):
        self.data = data
   
    def __getitem__(self, index):
        return self.data[index]

my_list = MyList([1, 2, 3, 4, 5])
print(my_list[0]) 


Hope this helps.
Best,
Tsvetelin

Submit an answer