Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print something, and then call a function with a print on the same line?

In Python I have a function that prints something. I want to print something beforehand on the same line.

So, I use the following code

print 'The hand is', displayHand(hand)

def displayHand(hand):

    for letter in hand.keys():
        for j in range(hand[letter]):
             print letter,              # print all on the same line
    print                               # print an empty line

What happens however is that the print within the function is called by the print outside the function.

How can I print an opening string, and then call my function?

like image 463
user1778351 Avatar asked Dec 28 '25 16:12

user1778351


1 Answers

Rename displayHand to renderHand and have it return a string.

like image 155
zmbq Avatar answered Dec 30 '25 06:12

zmbq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!