View Single Post
Old Feb 12th, 2007, 5:04 PM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
If you want to access an element of a tuple, you can use indices, in the same way you would an array or list:
python Syntax (Toggle Plain Text)
  1. result = (datetime.date(2007, 2, 9),)
  2. date = result[0]
  3. print date.strftime("%Y-%m-%d")
Or simply:
python Syntax (Toggle Plain Text)
  1. print result[0].strftime("%Y-%m-%d")
You can also assign a tuple to an set of variables to get its contents:
python Syntax (Toggle Plain Text)
  1. coords = (4, 6)
  2. x, y = coords
And for a tuple with a single value:
python Syntax (Toggle Plain Text)
  1. result = (datetime.date(2007, 2, 9),)
  2. date, = result
This notation when applied to only one value is a little obscure, however.
Arevos is offline   Reply With Quote