Python basics data structures

Title: Python Basics: Data Structures Date: 2017-10-26 13:26 Modified: 2017-10-30 13:26 Category: Python Tags: python, basics Slug: python-basics-data-structures Authors: Max Summary: Lists, tuples, dictionaries and sets.

List

ordered, mutable

x = []
y = [1,2]
print type(x)
print type(y)
<type 'list'>
<type 'list'>

Tuple

ordered, immutable

x = ()
y = (1,2)
print type(x)
print type(y)
<type 'tuple'>
<type 'tuple'>

Dictionary

unordered, mutable

x = {}
y = {'name': 'MaX', 'subject': "Data Science"}
print type(x)
print type(y)
<type 'dict'>
<type 'dict'>

Set

unordered, mutable, unique

x = {1,2,3,3,4}
print x
print type(x)
set([1, 2, 3, 4])
<type 'set'>