Because lists are sequences, indexing and slicing work the same way for lists as they do for strings.
Assuming following input −
L =["spam","Spam","SPAM!"]
Source
http://www.tutorialspoint.com
Python Expression | Results | Description |
---|---|---|
L[2] | "SPAM!" | Offsets start at zero |
L[-2] | "Spam" | Negative: count from the right |
L[1:] | ["Spam", "SPAM!"] | Slicing fetches sections |
کلمات کلیدی: