-1

I have a class called deck, it stores a list of integers, I need to print those integers so I used

def printdeck(self):
    print(" ".join(map(str,self.deck)))

It works and all but it returns "none" after use. I'd like it not to print "none" but I've no idea how to stop that. Any ideas?

styvane
  • 59,869
  • 19
  • 150
  • 156

1 Answers1

0

This is because you're not actually returning anything, so the function defaults to returning None.

A better alternative is to return your joined string, and then print that result:

def getdeck(self):
    return " ".join(map(str,self.deck))

print(getdeck())

Note that if you keep your function in this form:

def printdeck(self):
    print(" ".join(map(str,self.deck)))

it will work as you intend to, but it returns None. If you print the return value, then you will see None being printed.

Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94
  • You could keep it the second way but return an empty string to avoid returning None. – Rich Jan 16 '20 at 05:13