If the intention is to just concatenate it.

using str.format():

MyID = 'X12345'    
MasterFile_Name = r'C:\Users\ABC\{}\DEF\File - Test.xlsx'.format(MyID)    
print(MasterFile_Name)
Answer from DirtyBit on Stack Overflow
🌐
Python
docs.python.org › 2.0 › ref › string-catenation.html
2.4.2 String literal concatenation
Note that this feature is defined at the syntactical level, but implemented at compile time. The `+' operator must be used to concatenate string expressions at run time. Also note that literal concatenation can use different quoting styles for each component (even mixing raw strings and triple ...
🌐
ReqBin
reqbin.com › code › python › qlnh9kuj › python-concatenate-strings-example
How to concatenate strings in Python?
December 20, 2022 - The simplest and most commonly used method is the "+" operator. If you have a list of strings and want to concatenate them using the same separator between them, use the string.join() method.
🌐
Real Python
realpython.com › python-string-concatenation
Efficient String Concatenation in Python – Real Python
November 24, 2024 - Perhaps the quickest way to achieve concatenation is to take two separate strings and combine them with the plus operator (+), which is known as the concatenation operator in this context: ... >>> "Hello, " + "Pythonista!"
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-concatenation
How To Concatenate Strings in Python | DigitalOcean
2 weeks ago - When dealing with lists or sequences of strings, it’s often necessary to concatenate them into a single string. The join() method is an efficient way to do this, especially when working with large lists. It allows you to specify a delimiter to separate the elements in the list, making it ...
🌐
Vskills
vskills.in › home › escape sequence and string concatenation and format method
Escape sequence and string concatenation and format method - Tutorial
April 12, 2024 - # Using escape sequences print("Hello, world!\n") # String concatenation first_name = "John" last_name = "Doe" full_name = first_name + " " + last_name print("My name is " + full_name + ".") # Using the format method age = 25 occupation = "developer" print("I am {} years old and work as a {}.".format(age, occupation)) ... Hello, world! My name is John Doe. I am 25 years old and work as a developer. https://www.vskills.in/certification/certified-python-developer
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-raw-string
How To Use Python Raw String | DigitalOcean
March 3, 2026 - A Python raw string cannot end with an odd number of backslash characters. Writing r"hello\" will raise a SyntaxError because the backslash escapes the closing quote. To create a string that ends with a backslash, you can use concatenation: r"hello" + "\\" or use a normal string with a double ...
🌐
W3Schools
w3schools.com › python › python_strings_concatenate.asp
Python - String Concatenation
Remove List Duplicates Reverse ... Certificate Python Training ... To concatenate, or combine, two strings you can use the + operator....
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python
Concatenate Strings in Python: +, +=, join(), and more | note.nkmk.me
May 19, 2025 - This article explains how to concatenate strings or join a list of strings in Python. Concatenate Strings: +, +=The + OperatorThe += OperatorConcatenate Consecutive String Literals The + Operator The ...
🌐
mkaz.blog
mkaz.blog › working-with-python › strings
Strings - mkaz.blog
February 4, 2023 - You can use single or double quotes to specify a string in Python, this does not change the interpretation of the string like in PHP.
🌐
Python Tutorial
pythontutorial.net › home › python string methods › 7 ways to concatenate strings in python
7 Ways to Concatenate Strings Into a String in Python
December 28, 2020 - In this example, Python substitutes a %s in the literal string by corresponding string variable in the tuple that follows the % operator. You can use the format() method to concatenate multiple strings into a string.
🌐
UC Berkeley Statistics
stat.berkeley.edu › ~spector › extension › python › notes › node17.html
Concatenation
>>> first + " " + second 'black jack' When the strings you want to concatenate are literal string constants, that is, pieces of text surrounded by any of the quotes that python accepts, you don't even need the plus sign; python will automatically concatenate string constants that are separated by whitespace:
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-concatenation
Python String Concatenation - GeeksforGeeks
July 12, 2025 - Use join() function to concatenate strings with a specific separator. It’s especially useful when working with a sequence of strings, like a list or tuple. If no separator is needed then simply use join() with an empty string.
🌐
Python documentation
docs.python.org › 3 › reference › lexical_analysis.html
2. Lexical analysis — Python 3.14.4 documentation
February 23, 2026 - Except at the beginning of a logical line or in string literals, the whitespace characters space, tab and formfeed can be used interchangeably to separate tokens: ... Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Raw Strings in Python | note.nkmk.me
May 18, 2023 - To avoid this issue, you can either ... '\\' print(path2 == rpath2) # True ... You can use the built-in function repr() to transform a regular string into its raw string equivalent. Built-in Functions - repr() — Python 3.11.3 ...
🌐
Edureka Community
edureka.co › home › community › categories › python › what is the preferred way to concatenate strings...
What is the preferred way to concatenate strings in python | Edureka Community
December 21, 2018 - Since Python's string can't be changed, I was wondering how to concatenate a string more ... question would be did something change in Python 3?
Top answer
1 of 15
193

The whole misconception about python's raw strings is that most of people think that backslash (within a raw string) is just a regular character as all others. It is NOT. The key to understand is this python's tutorial sequence:

When an 'r' or 'R' prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string

So any character following a backslash is part of raw string. Once parser enters a raw string (non Unicode one) and encounters a backslash it knows there are 2 characters (a backslash and a char following it).

This way:

r'abc\d' comprises a, b, c, \, d

r'abc\'d' comprises a, b, c, \, ', d

r'abc\'' comprises a, b, c, \, '

and:

r'abc\' comprises a, b, c, \, ' but there is no terminating quote now.

Last case shows that according to documentation now a parser cannot find closing quote as the last quote you see above is part of the string i.e. backslash cannot be last here as it will 'devour' string closing char.

2 of 15
176

The reason is explained in the part of that section which I highlighted in bold:

String quotes can be escaped with a backslash, but the backslash remains in the string; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the string, not as a line continuation.

So raw strings are not 100% raw, there is still some rudimentary backslash-processing.

🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › python string concatenation explained
Python String Concatenation Explained
November 20, 2025 - Python installed (see how to install Python on Ubuntu, Windows, macOS, and Rocky Linux). Access to the command line. An IDE or text editor for code examples. String concatenation in Python refers to the process of joining two or more strings together to form a single string.
🌐
Mimo
mimo.org › glossary › python › raw-strings
Python Raw String: Syntax, Use Cases, and Examples
When you prefix a [string](https://mimo.org/glossary/python/string with r or R, Python skips processing escape sequences within it. ... Raw strings behave like normal strings in most other respects. You can slice them, concatenate them, and loop over them the same way you do with regular strings.