Collections

Python Collections


Python collections refer to specialized data structures available in the Python programming language that provide more advanced and efficient ways to store, manipulate, and manage data. Collections in Python are containers that are used to store collections of data
General purpose built-in containers of Python programming language are listed below:

List

In Python, list is one of the basic data structure useful to store multiple data items. The lists are ordered and have a definite count. 

Lists are mutable sequences, typically used to store collections of homogeneous items. But lists can also be used to store items with different data type. The elements in a list are identified by it's index number. Index number begins with 0.


Creating list in Python

Following code will create the lists with names: squares and banks

# List of numbers

>>> squares = [1, 4, 9, 16, 25]
>>> squares
[1, 4, 9, 16, 25]

# List of words

>>> banks = ['sbi', 'hdfc', 'icici']
>>> banks
['sbi', 'hdfc', 'icici']


Accessing values from a List 

Following code can be used to access values from a list.


>>> banks = ['sbi', 'hdfc', 'icici']
>>> banks
['sbi', 'hdfc', 'icici']

# prints first value from a List
>>> print(banks[0]
sbi



Brief note on Python Collections >

< Read more about Python List >


For more details, you can refer detailed documentation available at URL: https://docs.python.org/3/library/stdtypes.html


* * * * *

<  Back to Home Page >


No comments:

Post a Comment