Access List Elements

Access list elements

List items are indexed. You can access list element by index. First element index will be 0. The second element index will be 1, and so on.

Syntax

list_name[index]

See Output

Access list elements by negative index

The negative index allows you to access elements starting from the end of the list.

See Output

Note: Remember that the first item has index 0.


Range of Indexes

You can use range of indexes to get list elements.
You can use the negative indexes to get list elements.

Syntax

list_name[start:end]

See Output

Leave the start index

You can leave the start index. In this case first element index will be use as the start.

Syntax

list_name[:end]

See Output

Leave the end index

You can leave the end index. In this case last element index will be use as the end.

See Output

How to check an element exists or not in list

Membership operator(in, not in) is used to check element exist or not in the list.

See Output

About Us

Comsysapp.com is an educational website. Students and software developers can learn programming language tutorials. Comsysapp is very useful for beginners and professional developers. Comsysapp provides tutorial in easy language. Comsysapp.com has focus on simplicity.

Services

Comsysapp.com provides free tutorials like c, html, css, etc. All tutorials are free for beginner and professionals.


Terms of Use

comsysapp.com is not responsible for any mistake. We are not responsible if information made available on our website is incomplete or invalid. But comsysapp.com always try for zero-zero mistake.

Privacy policy

comsysapp.com does not collect any data from users. We use Google AdSense advertising on our website. We never ask personal or private information.


Sitemap

sitemap

copyright © 2023