Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I change a string.
#2
var = 'When parents goWhat do they listen toWhy'
words = ['When', 'Why', 'What', 'How']
for word in words:
    if not var.startswith(word):
        var = var.replace(word, f'. {word}')
print(var)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
How can I change a string. - by Mike Ru - Jun-03-2020, 10:03 AM
RE: How can I change a string. - by buran - Jun-03-2020, 10:13 AM
RE: How can I change a string. - by Mike Ru - Jun-03-2020, 10:39 AM
RE: How can I change a string. - by buran - Jun-03-2020, 10:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  change string in MS word Mr_Blue 8 3,215 Sep-19-2021, 02:13 PM
Last Post: snippsat
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 2,490 May-24-2021, 08:48 AM
Last Post: bowlofred
  Change string into Dict Robin_at_Cantelli 2 2,883 Mar-05-2020, 10:37 AM
Last Post: vishalhule
  "replace() method" fails to change string pw928gts 4 3,351 Nov-30-2018, 05:48 PM
Last Post: nilamo
  Change values in string multiline DavidFernandez 4 3,028 Aug-26-2018, 08:09 PM
Last Post: buran

Forum Jump:

User Panel Messages

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