TypeError: unsupported operand type(s) for +: 'builtin_function_or_method' and 'str'

class Dog:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def sit(self):
        print(str(self.name).title + "is  now  sitting.")

    def roll_over(self):
        print(str(self.name).title+"roll over")

mydog = Dog('giugui',8)
mydog.name
mydog.sit()
mydog.roll_over()
class Dog:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def sit(self):
        print(self.name + "is  now  sitting.")

    def roll_over(self):
        print(self.name+"roll over")

mydog = Dog('giugui',8)
mydog.sit()
mydog.roll_over()

去掉.title之后就对了,我也不清楚什么原因...

然后python 2.7也不会报错,3.7才会报错

你可能感兴趣的:(python)