Thursday, December 24, 2015

python in-built data types

list vs array :
List can hold heterogeneous objects while array can't. For doing math on arrays, prefer numpy.
Source :

list vs tuple :
tuples are fixed size and faster. Some tuples can be used as dictionary keys (specifically, tuples that contain immutable values like strings, numbers, and other tuples). Lists can never be used as dictionary keys, because lists are not immutable.

but unless you have a specific reason, always use list.

test_list = []
test_tuple = ()
test_dict = {}

No comments:

Blog Archive