Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, I would like to mapping a path. I have 2 string to identify that path.

What I have tried:

Python
str1 = "myname"
str2 = "112233"

path = "D:\folder\str1\str2"


I need to do like that.
Anyone can help please. Thanks a lot
Posted
Updated 9-Mar-21 23:31pm

1 solution

You can use the '+' symbol for string concatentation
Python
path = "D:\folder\" + str1 + "\" + str2
Some reference material Splitting, Concatenating, and Joining Strings in Python – Real Python[^]

As this is specifically a path then you could also use Python | os.path.join() method - GeeksforGeeks[^]
Python
path = os.path.join("D:\folder", str1, str2)
 
Share this answer
 
v2
Comments
Member 14156312 10-Mar-21 5:37am    
Thank you Buddy

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900