小编Mak*_*kin的帖子

Python中的多个函数

我们有一些变量或其他实例:a ='?'.我们有这样的输入:

f = a(3112).bas(443).ssad(34) 
Run Code Online (Sandbox Code Playgroud)

当我们打字

print(f)
Run Code Online (Sandbox Code Playgroud)

输出应该是:

3112a-443bas-34ssad
Run Code Online (Sandbox Code Playgroud)

我已经尝试了一些方法来解决这个问题,并找到了有关链接的信息,但我仍然遇到了问题.我不能将类名返回给字符串的brginning.

这,我有:

class A():       

    def __getattribute__(self, item):
        print (str(item))
        return super(A, self).__getattribute__(item)    

    def __init__(self, x):
        self.x = x
        print (str(x))

    def b(self, item):
        print (str(item))        
        return self

    def c(self, item):
        print (str(item))
        return self

    def d(self, item):
        print (str(item))
        return self

A(100).b(200).c(300).d(400)
Run Code Online (Sandbox Code Playgroud)

我的输出:

100
b
200
c
300
d
400
Run Code Online (Sandbox Code Playgroud)

但我无法在一个字符串中连接它.

python python-3.x

7
推荐指数
2
解决办法
197
查看次数

标签 统计

python ×1

python-3.x ×1