【问题标题】:obj.name() object is not callable [closed]obj.name() 对象不可调用 [关闭]
【发布时间】:2021-08-07 23:28:51
【问题描述】:
    #polymorphism
class father:
    def __init__(self,firstname,lastname,age):
        self.name=firstname
        self.secoundname=lastname
        self.age=age
    def name(self):
        print("name"+self.name+"secoundname"+self.secoundname)
    def age(self):
        print("age"+str(self.age))
class son(father):
    def name(self):
        print("name"+self.name+"secoundname"+self.secoundname)
class daughter(father):
    def name(self):
        print("name"+self.name+"secoundname"+self.secoundname)
        
obj=father("k","a",23)
obj1=son("A","f",2)
obj2=daughter("f","y",6)
obj.name()
obj.age()
obj1.name()
obj1.age()
obj2.name()
obj2.age()
        
 

  

   

   > Blockquote


   **giving an error

块引用 obj.name() 'str' 对象不可调用 上面出了什么问题,这只是一些愚蠢的错误,也许是 是带有函数类和对象的代码,定义的对象是 不正确或无法弄清楚的问题是什么? 帮帮我**

【问题讨论】:

  • 缩进太远了。将 if elif elif 和 else 退格,使其与输入的缩进级别相同。
  • 看看你的缩进:elif 都不匹配if

标签: python typeerror


【解决方案1】:

学习缩进



a = int (input("x"))
b = int (input ("y"))
c = int (input("z "))
if a ==b==c:
     print ("all equal")
elif(a>b and a>c):
    print("x is greatest")
elif(b>c and b>a):
    print("y is greatest ")
else :
    print("z is greatest")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    • 2020-11-20
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    相关资源
    最近更新 更多