Question : t = 12345, 54321, "hello!"

t = 12345, 54321, "hello!"
print t[0]


what if I want t to have multiple entries of t?

as in that 3 items is an entry.

Answer : t = 12345, 54321, "hello!"

You can store the tuples in some container, for example in the list. It depends on how do you want to access the entries later, if you want to search for them somehow, if the order of the entries is important or not.

Try the following snippet. You will get the result like this:

C:\tmp\__python\>a.py
The number of entries: 4
('aaa', 'bbb', 123)
('aa', 'bb', 12)
('a', 'b', 1)
('xxx', 'yyy', 'zzz')
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
t1 = ('aaa', 'bbb', 123)
t2 = ('aa', 'bb', 12)
t3 = ('a', 'b', 1)
 
entries = []
 
entries.append(t1)
entries.append(t2)
entries.append(t3)
 
entries.append( ('xxx', 'yyy', 'zzz') ) 
 
print 'The number of entries:', len(entries)
for entry in entries:
    print entry
Open in New Window Select All
Random Solutions  
 
programming4us programming4us