Learning immediately: https://edu.csdn.net/course/play/24797/282186?utm_source=blogtoedu
import random import types class Testa: def __init __ (self, name = "testa" age = 0) self.name = name self.age = age print ( "名字:% s年龄:% d '% (name, age)) class testB: def tesbb (self, name = "testbb ') self.name = name of the random.randint = (10, 99) testa () s = testa (the' test ') ta.name ta2 = testa (the 'test' av) ta.name, ta.age TA3 = testa (age = av, name = "testAAAA ') print (" - "* 30) tEA = testa () def test (self): print (" testing函数') tea.testAA = test tea.testAA (tEA) print ( "-"* 30) tea.testBB = types.MethodType(testaa, tea) tea.testBB() # del tea.testAA tea.testAA(tea) print('-' * 30) teb = testB() def testcolor(self): print('color:red') teb.color = 'red' print(teb.color) teb.color = types.MethodType(testcolor, teb) teb.color()