繁体   English   中英

如何在 Python 中使用 f-string 进行字典格式

[英]How can I do a dictionary format with f-string in Python

我的代码如下

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = f'{"siteUrls": {aaa}}'
print(REQUEST)

我试过了

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": {}}.format(aaa)
print(REQUEST)

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": %s}%aaa
print(REQUEST)

他们都没有工作
请求必须是字典。
请帮忙。

尝试这个

aaa = "['https://google.com', 'https://yahoo.com']"
REQUEST = {"siteUrls": f"{aaa}"}
print(REQUEST)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM