Firstly I am a beginner in python and this is where I got struck
Here class card returns a string
When I print the list itself without giving an index it shows me a garbage value, but when I give an index it shows me the value that I want. I don't know why this is happening.
class Card:
def __init__(self,suit,rank):
self.suit=suit
self.rank=rank
def __str__(self):
return f'{self.rank} of {self.suit}'
allcards=[]
allcards.append(Card('Spades','Jack'))
print(allcards)
Output: [<__main__.Card object at 0x0000013B5E72EFD0>]
class Card:
def __init__(self,suit,rank):
self.suit=suit
self.rank=rank
def __str__(self):
return f'{self.rank} of {self.suit}'
allcards=[]
allcards.append(Card('Spades','Jack'))
print(allcards[0])
Output: Jack of Spades
I want to print the list by using the first case how can I?