Python Forum
Using tuples or Re to replace 5 strings with one
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using tuples or Re to replace 5 strings with one
#6
each item that comes after the format statement must have a corresponding '{}' in the print body.
thus, your statement:
print('Rock1[0]: {}, ROck1[4]: {}'.format(Rock1[0], Rock1[2], Rock1[3], Rock1[4]))
there is no slot for Rock[3] and Rock[4] doesn't exist! Remember this is zero based, so indexes are 0,1,2,3
You didn't use Rock[1] which is the second item in the list

See what I'm talking about?

it would have to be something like:
print('Rock1: {}, Rock2: {} Rock3: {} Rock4: {} '.format(Rock[0], Rock[1], Rock[2], Rock1[3]))
Reply


Messages In This Thread
RE: Using tuples or Re to replace 5 strings with one - by Larz60+ - Aug-23-2017, 03:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 809 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,814 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Finding multiple strings between the two same strings Slither 1 2,543 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  Search & Replace - Newlines Added After Replace dj99 3 3,430 Jul-22-2018, 01:42 PM
Last Post: buran
  lists, strings, and byte strings Skaperen 2 4,259 Mar-02-2018, 02:12 AM
Last Post: Skaperen
  search and replace first amount of strings instances with one thing and a second amou chickflick91 7 5,614 Sep-26-2017, 05:13 PM
Last Post: chickflick91
  replace specific words in strings Sama 3 3,687 Jul-23-2017, 01:51 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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