简体   繁体   English

TypeError:必须为str,而不是buildin_function_or_method

[英]TypeError: must be str, not builtin_function_or_method

I have a bit of a problem at the moment, I'm quite new to python and to people who code a lot this might seem really easy to answer. 目前,我有一个问题,对于python和很多代码编写人员来说,我是一个新手,这似乎很容易回答。 We've been tasked to do a '99 bottles of beer on the wall' challenge and I wanted to make mine slightly better by asking the user what they'd like in the bottle. 我们的任务是挑战“墙上的99瓶啤酒”,我想通过询问用户他们想要的瓶子来使我的啤酒稍微好一点。 However I keep getting an error: TypeError: must be str, not builtin_function_or_method 但是我不断收到error: TypeError: must be str, not builtin_function_or_method

input("What would you like inside your bottle?")

def sing(b, end):
    print(b or 'No more', 'bottle'+('s' if b-1 else ''), end)

for i in range(99, 0, -1):
    sing(i, 'of'+input+'on the wall,')
    sing(i, 'of'+input+',')
    print('Take one down, pass it around,')
    sing(i-1, 'of'+input+'on the wall.\n')

any help would be much appreciated, thanks :3 任何帮助将不胜感激,谢谢:3

input() method returns value to be assigned to a variable. input()方法返回要分配给变量的值。 Compare with the docs . 与文档进行比较 Now you are referencing a method not a variable. 现在,您引用的是方法而不是变量。

You need something like 你需要类似的东西

something = input('Say sth. ')
print(something)

input is a builtin function, so when you do 'of'+input+'on the wall' , you just try to concatenate a function to a string, which doesn't make a lot of sense ;) input是一个内置函数,因此当您执行'of'+input+'on the wall' ,您只是尝试将一个函数连接到一个字符串,这没有多大意义;)
(the interpreter is explicitly telling you that) (解释器明确告诉您)

input returns a string you doesn't assign to a variable, so try user_input = input("What would you like inside the bootle?") and then using user_input instead of input in your code. input返回的字符串是您未分配给变量的,因此请尝试使用user_input = input("What would you like inside the bootle?") ,然后使用user_input代替代码中的input

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到错误“必须是str,而不是builtin_function_or_method” - I get the error “must be str, not builtin_function_or_method” TypeError:无法在python中连接'str'和'builtin_function_or_method'对象 - TypeError: cannot concatenate 'str' and 'builtin_function_or_method' objects in python Pygame“ TypeError:必须为2个项目的序列,而不是Builtin_function_or_method” - Pygame “TypeError: must be 2-item sequence, not builtin_function_or_method” TypeError:参数1必须是pygame.Surface,而不是buildin_function_or_method - TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method TypeError:float()参数必须是字符串或数字,而不是“ builtin_function_or_method” - TypeError: float() argument must be a string or a number, not 'builtin_function_or_method' TypeError:“ builtin_function_or_method”不可迭代 - TypeError: 'builtin_function_or_method' is not iterable TypeError:“ builtin_function_or_method”对象无法下标 - TypeError: 'builtin_function_or_method' object is unsubscriptable 类型错误:'builtin_function_or_method' 对象不可下标 - TypeError: 'builtin_function_or_method' object is not subscriptable TypeError:“ builtin_function_or_method”对象不可下标 - TypeError: 'builtin_function_or_method' object is not subscriptable TypeError:无法隐式地将'builtin_function_or_method'对象转换为str - TypeError: Can't convert 'builtin_function_or_method' object to str implicitly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM