Python 3.x 如何在读取文件路径时使用变量?

Python 3.x 如何在读取文件路径时使用变量?,python-3.x,Python 3.x,我试图简化代码,而不是改变一堆变量 例如: title = "example" filepath = r"C:\Users\User\Desktop\Research\title" 我希望输出为C:\Users\User\Desktop\Research\example,但它返回带引号的字符串 如何让它改为读取“title”变量?将格式化字符串与原始字符串一起使用 title = "example" filepath = rf"C:\Users\User\Desktop\Research\{t

我试图简化代码,而不是改变一堆变量

例如:

title = "example"
filepath = r"C:\Users\User\Desktop\Research\title"
我希望输出为
C:\Users\User\Desktop\Research\example
,但它返回带引号的字符串


如何让它改为读取“title”变量?

将格式化字符串与原始字符串一起使用

title = "example"
filepath = rf"C:\Users\User\Desktop\Research\{title}"
输出:

>>> print(filepath)
C:\Users\User\Desktop\Research\example
>>>