Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a simple value to a string

Tags:

python

string

If I have a string lets say ohh

path2 = '"C:\\Users\\bgbesase\\Documents\\Brent\\Code\\Visual Studio' 

And I want to add a " at the end of the string how do I do that? Right now I have it like this.

path2 = '"C:\\Users\\bgbesase\\Documents\\Brent\\Code\\Visual Studio'
w = '"'
final = os.path.join(path2, w)
print final

However when it prints it out, this is what is returned:

"C:\Users\bgbesase\Documents\Brent\Code\Visual Studio\"

I don't need the \ I only want the "

Thanks for any help in advance.

like image 645
bbesase Avatar asked Feb 23 '26 12:02

bbesase


2 Answers

How about?

path2 = '"C:\\Users\\bgbesase\\Documents\\Brent\\Code\\Visual Studio' + '"'

Or, as you had it

final = path2 + w

It's also worth mentioning that you can use raw strings (r'stuff') to avoid having to escape backslashes. Ex.

path2 = r'"C:\Users\bgbesase\Documents\Brent\Code\Visual Studio'
like image 188
Theo Belaire Avatar answered Feb 26 '26 02:02

Theo Belaire


just do:

path2 = '"C:\\Users\\bgbesase\\Documents\\Brent\\Code\\Visual Studio' + '"'
like image 31
Gus E Avatar answered Feb 26 '26 01:02

Gus E