codeholic24
codeholic24

Reputation: 995

How to print following text on new line every pair?

I have text which I want to show on newlines:

strname='A->1 B->2 C->1 Z->4'

Expected output:

A->1
B->2
C->1
Z->4

When I used end=, it does not give any output:

strname='A->1 B->2 C->1 Z->4'
output= (strname, end='\n')

Upvotes: 1

Views: 42

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521269

Use replace():

strname = 'A->1 B->2 C->1 Z->4'
output = strname.replace(' ', '\n')
print(output)

This prints:

A->1
B->2
C->1
Z->4

Upvotes: 1

Related Questions