13:STRUCTURE AND UNIONS

13.2.1, page number:203

In [1]:
from collections import namedtuple
MyStruct = namedtuple("MyStruct", "regno fees")

integer = MyStruct("1234", " ")
real = MyStruct(" ","320.17")
integer=integer._replace(fees=real.fees)
real=real._replace(regno=integer.regno)

print "Reg_no : ",real.regno,",Reg.no : ",integer.fees
Reg_no :  1234 ,Reg.no :  320.17

13.3.1, page number:203

In [2]:
from collections import namedtuple
MyStruct = namedtuple("MyStruct", "regno fees")


student = MyStruct("1234", "320.17")

print "Reg.no : ",student.regno,",Reg.no : ",student.fees
Reg.no :  1234 ,Reg.no :  320.17

13.4.1, page number:204

In [3]:
from collections import namedtuple
MyStruct = namedtuple("MyStruct", "regno fees")

integer = MyStruct("1234", "320.17")
real = MyStruct("","")
real=real._replace(regno=integer.regno,fees=integer.fees)

print "Reg_no : ",real.regno,",Reg.no : ",real.fees
Reg_no :  1234 ,Reg.no :  320.17