YouTip LogoYouTip

Python3 Att List Index

# Python3.x Python3 List index() Method [![Image 3: Python3 Lists](#) Python3 Lists](#) * * * ## Description The index() method is used to find the index position of the first matching item in a list. ## Syntax The syntax for the index() method is: list.index(x[, start[, end]]) ## Parameters * x -- The object to search for. * start -- Optional, the starting position of the search. * end -- Optional, the ending position of the search. ## Return Value This method returns the index position of the searched object. If the object is not found, it raises an exception. ## Example The following examples demonstrate the usage of the index() method: ## Example 1 #!/usr/bin/python3 list1 =['Google','Tutorial','Taobao'] print('Tutorial index value is', list1.index('Tutorial')) print('Taobao index value is', list1.index('Taobao')) The output of the above example is: Tutorial index value is 1Taobao index value is 2 ## Example 2 #!/usr/bin/python3 list1 =['Google','Tutorial','Taobao','Facebook','QQ'] # Search starting from a specified position print('Tutorial index value is', list1.index('Tutorial',1)) The output of the above example is: Tutorial index value is 1 [![Image 4: Python3 Lists](#) Python3 Lists](#)
← Python3 Att List PopPython3 Att List Index β†’