Python Forum
How to print string multiple times separated by delimiter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print string multiple times separated by delimiter
#1
Hi,
Is there any way to print single string multiple tiles in same line and separated by dilimiter:


print(*range(5), sep=", ") ## this is working
s = 'abcd'
print(s*2) ## this is working
print((s*2),sep=' and ') ## this is not working
Reply
#2
It is not working because it is one string item
s = 'abcd'
print(*(s for _ in range(2)), sep=' and ')
Output:
abcd and abcd
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,308 Nov-09-2023, 10:56 AM
Last Post: mg24
  splitting file into multiple files by searching for string AlphaInc 2 814 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Context-sensitive delimiter ZZTurn 9 1,393 May-16-2023, 07:31 AM
Last Post: Gribouillis
  Read csv file with inconsistent delimiter gracenz 2 1,140 Mar-27-2023, 08:59 PM
Last Post: deanhystad
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 851 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,087 Aug-19-2022, 08:07 PM
Last Post: Winfried
  Remove a space between a string and variable in print sie 5 1,706 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Matching multiple parts in string fozz 31 6,059 Jun-13-2022, 09:38 AM
Last Post: fozz
  Can you print a string variable to printer hammer 2 1,891 Apr-30-2022, 11:48 PM
Last Post: hammer
  Delimiter issue with a CSV file jehoshua 1 1,218 Apr-19-2022, 01:28 AM
Last Post: jehoshua

Forum Jump:

User Panel Messages

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