class mydict(dict)def __setitem__(selfkeyval)print('setting key and value!'dict __setitem__(selfkeyvaldd mydict(dd[' ' dd[' ' for key in dd keys()print('{ }={ }format(keydd[key])outputsetting key and valuesetting key and valuea= = let' extend our previous examplebelow we have called two magic methods called __getitem__ and __setitem__ better invoked when we deal with list index mylist inherits from 'listobject but indexes from instead for class mylist(list)inherits from list def __getitem__(selfindex)if index = raise indexerror if index index index return list __getitem__(selfindexthis method is called when we access value with subscript like [ def __setitem__(selfindexvalue)if index = raise indexerror if index index index