【问题标题】:How can I do a dictionary format with f-string in Python如何在 Python 中使用 f-string 进行字典格式
【发布时间】:2022-07-12 00:40:50
【问题描述】:

我的代码如下

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)

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

【问题讨论】:

    标签: python dictionary formatting f-string


    【解决方案1】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 2017-09-15
      • 2023-02-16
      • 1970-01-01
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      • 2022-08-06
      • 1970-01-01
      相关资源
      最近更新 更多