【发布时间】:2015-01-22 21:25:39
【问题描述】:
我是初学者。为了学习,我必须在 python 中编写一个类,它最多接受 3 个不同的参数(a,b,c):类似于
class random(object):
def __init__(self,a,b,c):
blah blah blah
如何做到这一点:
-
如果没有输入参数,它只做一件事。
例如:
“test=random()”,在这种情况下假设 a=b=c=0
-
如果输入一个参数,它会做另一件事。
例如:
"test=random(2)", in this case a=2 ,b=c=0, and then run some case specific codes/instrutctions 等等
类似于内置函数/类“范围”,您可以在其中使用
范围(9) 范围(3,9) 范围(3,9,2)
如果你知道我的意思。
谢谢
【问题讨论】:
标签: python class variables arguments init