Python, print string on the same line for screen output

Viewed 76

I am lost on printing a character on the same line.

For example

 card = "--Diamonds--"

Output needed: --Diamonds-- --Diamonds-- --Diamonds-- --Diamonds-- --Diamonds--

The same string variable (not a list) to be repeated on a single line. I don't want it to be a list at this stage, just an image for visuals.

Cheers

4 Answers

you could try to do it like this:

print(card*5)

Just do this:

card = "--Diamonds--"

print(card, card, card, card, card)

You can repeat it infitely just alway make a comma and then the variable

This also works:

    card = "--Diamonds--"
    for i in range(1, 6):
        print(card, end=' ')

This would output:

--Diamonds-- --Diamonds-- --Diamonds-- --Diamonds-- --Diamonds--

If you want there to be no spaces in between the words, you need to use:

    card = "--Diamonds--"
    for i in range(1, 6):
        print(card, end='')

output:

--Diamonds----Diamonds----Diamonds----Diamonds----Diamonds--

As a possible answer:

card = "--Diamonds--"
result = card + card + card + card + card
print(result)
Related