On , Siva Ranganath wrote:
Hi All,
please let me know few cases when we will go with Lists and tuples in
pyhton.
Lists are like vectors (since you're from a C++ background). They can
expand/contract depending on data and are also heterogeneous meaning
that all the elements needn't be of the same type. It's a flexible
container for holding things. Lists are often iterated over (e.g. for i
in all_documents) or indexed (e.g. students[5] to get the fifth
student).
Tuples are more like C structures in that they're used to hold a few
related things together. They have several behaviours similar to a list
(can be indexed, iterated over etc.) but are not mutable (you can't
add/remove elements from them). However, they're often used differently.
They're used as C structs but without names for the fields. So, points
in 2D space (x,y) are a good candidate for a tuple or maybe a colour in
RGB colourspace denoted by (r,g,b).
For a more in depth discussion, you should look at the official python
tutorial at https://docs.python.org/3.6/tutorial/
_______________________________________________
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers