python built-in data structures

python built-in data structures

In Python, there are several built-in data structures for holding collections of items. Here are a few of the most commonly used ones:

List: 

A list is an ordered, mutable, and heterogeneous collection of items. It is defined by square brackets [] and items are separated by commas. 

fruits = ['apple', 'banana', 'cherry'] print(fruits)

Tuple:

A tuple is similar to a list, but it is immutable and ordered. Tuples are defined by parentheses () and items are separated by commas.


fruits = ('apple', 'banana', 'cherry') print(fruits)

Dictionary:

A dictionary is an unordered collection of key-value pairs. It is defined by curly braces {} and keys are separated from values by colons.


fruits = {'apple': 10, 'banana': 20, 'cherry': 30} print(fruits)

Set:

A set is an unordered and unchangeable collection of unique items. It is defined by curly braces {} and items are separated by commas.


fruits = {'apple', 'banana', 'cherry'} print(fruits)


Comments

Popular posts from this blog

Market share of top programming languages python, java

python abstract class

python NumPy - Data science