__getitem__() function in python by R4R Team

- __getitem__() is a python function which is used for find the item in the list according to their index.

Syntax-

list.__getitem__(item)

Example

list is [1,2,3,5,6,7]
list__getitem__(2) return the value at 2nd index. i.e.value is 3


program-

l=[1,2,3,"one","two"]
print("List is ",l)

item=l.__getitem__(0)
print(item)

item=l.__getitem__(1)
print(item)

item=l.__getitem__(2)
print(item)

item=l.__getitem__(3)
print(item)

item=l.__getitem__(4)
print(item)


output-

List is [1, 2, 3, 'one', 'two']
1
2
3
one
two


-In this program, we have a list [1,2,3,"one","two"] then we find the index value and print them one by one.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!