Python Forum
Help getting a string out of regex
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help getting a string out of regex
#4
join() is an operator on a string, and it doesn't modify anything. It returns a new string.

Since you're not assigning the result of the join, the result is thrown away and y remains the same.

y = "Hello, world!"
l = ["one", "two", "three"]
y.join(l)
print(y)  # no change

y = y.join(l) # assigns the change back to y
print(y)    # now the change is seen
Output:
Hello, world! oneHello, world!twoHello, world!three
That said, I'm not sure you want to join() at all. It sounds like you just want to concatenate two strings. You can do that with a plus symbol if you have two strings.
Reply


Messages In This Thread
RE: Help getting a string out of regex - by bowlofred - Dec-01-2020, 10:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Regex: a string does not starts and ends with the same character Melcu54 5 2,473 Jul-04-2021, 07:51 PM
Last Post: Melcu54
  Please support regex for version number (digits and dots) from a string Tecuma 4 3,247 Aug-17-2020, 09:59 AM
Last Post: Tecuma
  regex match in a string batchen 4 3,263 Jan-20-2020, 08:48 AM
Last Post: batchen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020