我想知道如何在一行中打印多个链接,将它们从一个单独的行转换为在它们之间有空格并将它们放在同一行上。
示例:
https://www.google.co.uk
https://www.google.co.uk
https://www.google.co.uk
我希望它能打印出来:
https://www.google.co.uk https://www.google.co.uk https://www.google.co.uk
答案 0 :(得分:0)
这取决于字符串的来源,但如果它是一个简单的单字符串,则以下内容可以起作用:
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
请注意,某些字符串换行符可能包含' \ r \ n'太
答案 1 :(得分:-1)
尝试在print语句的末尾添加逗号:
links = ["https://www.google.co.uk","https://www.google.co.uk","https://www.google.co.uk"]
for link in links:
print link,