tutorial introduction tuples to create simple data structuresyou can pack collection of values together into single object using tuple you create tuple by enclosing group of values in parentheses like thisstock ('goog' address ('www python org' person (first_namelast_namephonepython often recognizes that tuple is intended even if the parentheses are missingstock 'goog' address 'www python org', person first_namelast_namephone for completeness and -element tuples can be definedbut have special syntaxa ( (item, item -tuple (empty tuple -tuple (note the trailing comma -tuple (note the trailing commathe values in tuple can be extracted by numerical index just like list howeverit is more common to unpack tuples into set of variables like thisnamesharesprice stock hostport address first_namelast_namephone person although tuples support most of the same operations as lists (such as indexingslicingand concatenation)the contents of tuple cannot be modified after creation (that isyou cannot replacedeleteor append new elements to an existing tuplethis reflects the fact that tuple is best viewed as single object consisting of several partsnot as collection of distinct objects to which you might insert or remove items because there is so much overlap between tuples and listssome programmers are inclined to ignore tuples altogether and simply use lists because they seem to be more flexible although this worksit wastes memory if your program is going to create large number of small lists (that iseach containing fewer than dozen itemsthis is because lists slightly overallocate memory to optimize the performance of operations that add new items because tuples are immutablethey use more compact representation where there is no extra space tuples and lists are often used together to represent data for examplethis program shows how you might read file consisting of different columns of data separated by commasfile containing lines of the form "name,shares,pricefilename "portfolio csvportfolio [for line in open(filename)fields line split(","split each line into list name fields[ extract and convert individual fields shares int(fields[ ]price float(fields[ ]stock (name,shares,pricecreate tuple (namesharespriceportfolio append(stockappend to list of records the split(method of strings splits string into list of fields separated by the given delimiter character the resulting portfolio data structure created by this program lib fl ff