DEV Community

Brayan Potosi
Brayan Potosi

Posted on • Updated on

Structured data in Python

Some examples of structured data in Python are lists, sets, dictionaries, etc., its main feature is store a lot of items in a single variable.
Next i will to explain it with examples.


Lists : These can store different types of data and no matter if the elements are repited. It is represented with [ ], these are mutable it means that one list can change during execution.

List_items_example = [1, 'cat', 1.23] 
Enter fullscreen mode Exit fullscreen mode

if you want to get a specific item can access by index .

print(List_items_example[1])

output : cat
Enter fullscreen mode Exit fullscreen mode

Sets : These are very used for store items which are not repeated, not is possible access to an element by index, it is represented with { }, these are immutable.

set_items_example = {'one', 'two',  3}
Enter fullscreen mode Exit fullscreen mode

Dictionaries : These are different because each item is composed of one key and value, can access to a value by the key and no by index, these are mutable.

dict_items_example = {'fruit': 'apple', 'number': 33, 'char': 'Z'}
Enter fullscreen mode Exit fullscreen mode

Getting a value

print(dict_items_example['fruit'])

output : apple
Enter fullscreen mode Exit fullscreen mode

Top comments (0)