Cheap VPS host selection
Provide server host evaluation information

Two methods of finding element position in python list

Sequence is the most basic data structure in Python. Each element in the sequence is assigned a number - its position, or index. The first index is 0, the second index is 1, and so on. Python has six built-in types of sequences, but the most common are lists and tuples. Today I would like to share with you two ways to find the location of elements in python list

1. Access a single element through index positioning, listname represents the name of the list, and index represents the index value of the element to be searched.

Grammatical structure

 listname [index]

2. Access multiple elements by slicing, listname represents the name of the list, and index represents the index value of the element to be searched.

Grammatical structure

 listname[ start : end :step]

example

 list  = [ 'Da Wei'  'Xiao Wei'  'Xiaowei' , one hundred and twenty-three ] print ( list [ zero ])   #The first element of the output list
 print ( list [ one : three ])   #Output the second to third elements
 print ( list [ two :])   #Output all elements from the third to the end of the list
Do not reprint without permission: Cheap VPS evaluation » Two methods of finding element position in python list