Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正在分析context.bot.send_message()中的变量_Python_Python 3.x_Telegram_Telegram Bot_Py Telegram Bot Api - Fatal编程技术网

Python 正在分析context.bot.send_message()中的变量

Python 正在分析context.bot.send_message()中的变量,python,python-3.x,telegram,telegram-bot,py-telegram-bot-api,Python,Python 3.x,Telegram,Telegram Bot,Py Telegram Bot Api,我目前在的帮助下开发一个机器人,我遇到了一个小问题 看到了吗?目标是,当用户运行命令时,机器人会回答一个先前从数据库中选择并保存在变量中的数字。让我们称之为var var = "12.321.231" def casosspain(update, context): context.bot.send_message( chat_id=update.effective_chat.id, text="Los casos confirmados en e

我目前在的帮助下开发一个机器人,我遇到了一个小问题

看到了吗?目标是,当用户运行命令时,机器人会回答一个先前从数据库中选择并保存在变量中的数字。让我们称之为var

var = "12.321.231"

def casosspain(update, context):
context.bot.send_message(
    chat_id=update.effective_chat.id,
    text="Los casos confirmados en españa son: "
)
我尝试在text=”“声明之后使用print(var),但它不起作用,因为它是关键字参数之后的位置参数

我的目标是打印出这一行:

Los casos confirmados en españa son: 12.321.231

你有什么想法可以让我这样做吗?非常感谢您的帮助

您可以使用python的f字符串

text = f"Los casos confirmados en españa son: {var}"
>>> var = "12.321.231"
>>> text = f"Los casos confirmados en españa son: {var}"
>>> print(text)
Los casos confirmados en españa son: 12.321.231