Browse Source

completed tupes examples by adding one for named tupes

master
T. Meissner 10 years ago
parent
commit
53bce1fa4d
1 changed files with 9 additions and 1 deletions
  1. +9
    -1
      python_3_oop/chapter06/tuples.py

+ 9
- 1
python_3_oop/chapter06/tuples.py View File

@ -1,4 +1,5 @@
import datetime
from collections import namedtuple
def middle(stock, date):
@ -11,4 +12,11 @@ tuple = ("GOOG", 613.30, 625.86, 610.50)
mid_value, date = middle(tuple, datetime.datetime.now())
print("middle value: {} at date {}".format(mid_value, date))
print("high value: {}".format(tuple[2]))
print(tuple[1:3])
print(tuple[1:3])
# named tuples
Stock = namedtuple("Stock", "symbol current high low")
stock = Stock("GOOG", 613.30, high=625.86, low=610.50)
print("{}: current={}, high={}, low={}".format(stock.symbol, stock.current,
stock.high, stock.low))

Loading…
Cancel
Save