>"+u-6ren">
gpt4 book ai didi

python - 我正在编写代码来获取用户输入并在 python 中提供其文档。但是用户输入中的字符串在python中是用引号引起来的

转载 作者:行者123 更新时间:2023-12-04 01:09:43 24 4
gpt4 key购买 nike

user_input = input("\nWhat can I help you with? ")
user_input = user_input.strip('"')
print("\n>>"+user_input.__doc__)

在上面的代码中,user_input.doc 导致了以下问题:

str(bytes_or_buffer[, encoding[, errors]]) -> strCreate a new string object from the given object. If encoding orerrors is specified, then the object must expose a data bufferthat will be decoded using the given encoding and error handler.Otherwise, returns the result of object.str() (if defined)or repr(object).encoding defaults to sys.getdefaultencoding().errors defaults to 'strict'.

当我将 user_input 与 __doc__ 一起使用时,任何人都可以帮助我删除 user_input 中的引号吗?

最佳答案

您可以使用 eval() :

user_input = input("\nWhat can I help you with? ")
user_input = user_input.strip('"')
print("\n>>"+eval(user_input).__doc__)

关于python - 我正在编写代码来获取用户输入并在 python 中提供其文档。但是用户输入中的字符串在python中是用引号引起来的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65246609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com