Python:类中的对象如何作为参数传入函数
2021-03-06 05:29
                         标签:info   tps   col   htm   argument   img   graph   test   port    只需要将类作为形参传入,接着就可在函数定义时直接运用该类中的对象了 例子,其中用到的 graphics.py 类 运行结果 Python:类中的对象如何作为参数传入函数 标签:info   tps   col   htm   argument   img   graph   test   port    原文地址:https://www.cnblogs.com/moyutime/p/14307248.html类中的对象如何作为参数传入函数
from graphics import *
win = GraphWin(‘test‘, 300, 300)
# 函数定义, 设置窗口背景色并且在窗口中画一条线段的函数
def setbgAndLine(graphics ,somewin, colour):
    somewin.setBackground(colour)
    somewin.setCoords(0,0,10,10)
    Line(Point(4,4), Point(6,6)).draw(somewin)
    input()  # 使窗口不自动关闭(因为ide里的窗口会闪现一下就消失)
    somewin.close()
# 函数调用
setbgAndLine(‘填补空缺‘, win, ‘red‘)
# missing 1 required argument

上一篇:Java中的对象比较
下一篇:Python:graphics类
文章标题:Python:类中的对象如何作为参数传入函数
文章链接:http://soscw.com/index.php/essay/60723.html