Back to Browse

PYTHON | Part - 4 | Lists in Python

116 views
Jun 26, 2020
17:49

Hello Everyone, Python offers a range of compound data types often referred to as sequences. The list is one of the most frequently used and very versatile data types used in Python. In Python programming, a list is created by placing all the items (elements) inside square brackets [], separated by commas. It can have any number of items and they may be of different types (integer, float, string, etc.). A list can also have another list as an item. This is called a nested list. How to access elements from a list? There are various ways in which we can access the elements of a list. List Index We can use the index operator [] to access an item in a list. In Python, indices start at 0. So, a list having 5 elements will have an index from 0 to 4. Trying to access indexes other than these will raise an IndexError. The index must be an integer. We can't use float or other types, this will result in TypeError. Nested lists are accessed using nested indexing. Negative indexing Python allows negative indexing for its sequences. The index of -1 refers to the last item, -2 to the second last item, and so on. We can access a range of items in a list by using the slicing operator :(colon). So, Stay Tuned for more. Check us out for more updates: Instagram - https://bit.ly/2WJioSw Facebook - https://bit.ly/2VckgCq Join our Whatsapp Group for regular updates and doubt solving. Whatsapp Group - https://bit.ly/2xDhcpP If you are having any suggestions for us to make your learning a better experience, write to us in the COMMENT section. Don't forget to LIKE, SHARE & SUBSCRIBE Thank You for watching!! #PYTHON #webdevelopment #ListsinPython #lists

Download

0 formats

No download links available.

PYTHON | Part - 4 | Lists in Python | NatokHD