为变量赋值,并在python中的另一个变量中使用它

2024-06-01 02:52:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手。我想要一些我们在壳牌公司使用的东西

new_folder=nice

folder1=/opt/$new_文件夹/nnn

我试图连接,也使用了%但它不起作用。在

有人能帮忙吗?在

谨致问候, B


Tags: 文件夹new公司folderniceopt新手问候
2条回答

就像这里的post解释:

"Hello %s, my name is %s" % ('john', 'mike') # Hello john, my name is mike".

所以对你来说:

new_folder = "nice"
folder1= "/opt/%s/nnn" % (new_folder)

您可以这样做:

new_folder = "nice"
folder1 = "/opt/{}/nnn".format(new_folder)
# or 
folder1 = "/opt/" + new_folder + "/nnn"

相关问题 更多 >