一个有多个参数但在 Python 中只接受其中一个参数的函数

问题描述 投票:0回答:0

我想知道我们如何编写一个具有多个已定义参数的函数,但我希望只传递其中一个。如果有帮助的话,我正在一个类的init函数中这样做......

class text():
    def __init__(self, c, tl, tr, bl, br):
        #For example I want to only accept one of these c, tl, tr, bl and br
        pass

另外,我是编程新手,所以如果我犯了一个愚蠢的错误。对不起。

我已经尝试过 if 语句来引发错误,但这太麻烦了。

python user-defined-functions
© www.soinside.com 2019 - 2024. All rights reserved.