Print语句给出不可调用的错误[关闭]

问题描述 投票:1回答:1
print = ('Tell me about your pet. ')
about_pet = input()

if 'dog'.lower() in about_pet == True :
    print('ah, a dog')
if 'cat'.lower() in about_pet == True :
    print ('ooh, a kitty')

print ('Thanks for the story')

当我运行此代码时,我收到一个错误:

str对象不可调用

是什么导致这个?

python callable
1个回答
3
投票

print = ('Tell me about your pet. ')将函数print覆盖为字符串。之后它不再是一个函数,所以每次你试图将它作为函数调用时,你都会遇到错误。

摆脱=所以你不会改变print是什么。

© www.soinside.com 2019 - 2024. All rights reserved.