我正在尝试将变量值包含到url 中
ip= sys.argv[1]
https://management.azure.com/Subscriptions/xxxxxx/resourceGroups/xxxxxx/providers/Microsoft.RecoveryServices/vaults/{ip}/backupProtectedItems?api-version=2019-05-13&
但是当我打印url时,我得到了如下所示,因为它是ip并没有取代
https://management.azure.com/Subscriptions/xxxxxx/resourceGroups/xxxxxx/providers/Microsoft.RecoveryServices/vaults/{ip}/backupProtectedItems?api-version=2019-05-13&
有人能推荐吗
假设您使用的是Python>=3.6并且尝试使用f-string,您需要在字符串文字前面加上f
,如下所示:
ip="11.22.33.44"
s = f"url/with/{ip}/and/stuff" #notice the f before the opening quote
print(s)
输出:
url/with/11.22.33.44/and/stuff