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

原文链接:Structured data in Python

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
No matter how complicated your life is, you have to maintain your elegance.
不论生活如何复杂,总要保持自己的那一份优雅
评论 抢沙发

请登录后发表评论

    暂无评论内容