python - 代码没有按照我想要的方式工作(python)
问题描述
def operator_updater(all_operators):
for operator in all_operators:
print(operator, sep=' ', end='', flush=True)
all_operators = ['|+|', '|-|', '|x|', '|/|']
op = input(f"Input Operator {operator_updater(all_operators)}: ")
#我希望它像这样打印输入运算符 |+| |-| |x| |/|:
#但这是结果--> |+| |-| |x| |/| 输入运算符无:
解决方案
您的operator_updater
函数在返回之前打印值。它也不会返回任何东西,这就是你看到 None 的原因。你可以做这样的事情,但可能有更好的方法去做。
def operator_updater(all_operators):
result = ''
for operator in all_operators:
result += operator + ' '
return result[:-1]
all_operators = ['|+|', '|-|', '|x|', '|/|']
op = input(f"Input Operator {operator_updater(all_operators)}: ")
推荐阅读
- python - str.同时包含多个值
- azure-devops - Azure Devops 管道,多分支触发器不起作用
- amazon-web-services - AWS CloudFormation 模板 - 必需值
- actions-on-google - 验证 Google Conversation v3 API 的 webhook 请求签名
- javascript - 基于至少两个参数的复杂决策
- java - 如何解决'线程“主”java.lang.NullPointerException中的异常'
- wordpress - Woocommerce PHP - 将产品图片添加到页面
- php - 将 WordPress 数据库表导出到包含所有元信息的 excel 文件
- php - Cake PHP 2 模型与查找器查询的关联
- python - how to replace XML values with values from a list