0

I want to know how I can print multiple links in one line transforming them from being in a separate line to having spaces between them and putting them on the same line.

Example:

https://www.google.co.uk
https://www.google.co.uk
https://www.google.co.uk

I want it to print this instead:

https://www.google.co.uk https://www.google.co.uk https://www.google.co.uk
  • 1
    Possible duplicate of [How to print without newline or space?](https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space) – PRMoureu Sep 27 '17 at 20:14
  • `print('url', 'url2', sep=' ')` or `print('url', end=' ') ;print('url2', end=' ') ...` – PRMoureu Sep 27 '17 at 20:21

2 Answers2

0

It depends on where your string is coming from, but if it is a simple single string then the following could work:

string_value = '''https://www.google.co.uk
                  https://www.google.co.uk
                  https://www.google.co.uk'''
# replace the newline character with a space
string_value.replace('\n', ' ')
>> https://www.google.co.uk https://www.google.co.uk https://www.google.co.uk

Please be aware that some string newlines may consist of the '\r\n' too.

Leroy
  • 430
  • 8
  • 12
-1

Try adding a comma to the end of the print statement:

links = ["https://www.google.co.uk","https://www.google.co.uk","https://www.google.co.uk"]
for link in links:
    print link,
Asleepace
  • 3,466
  • 2
  • 23
  • 36