0

I was trying to create a new class just today so I can organize pygame code (Learning Pygame/First Project) After making and setting up the class I realized that it had turned all of my parameter type variables into a tuple for no reason. I created a new py file for testing and created to different classes in it with the same everything (however one was copied from my other code the other wasnt) and for some stupid reason the one copied was a tuple and the one made from scratch wasnt. I tested it out some more and found that copying the innit function from the tuple one would result in a tupled variable. I also know that it isn't a part of my IDE due to me testing it in the python console seperate from my IDE and the same issue occured. All I can do now is ask you for your help and provide pictures and my code.

class Person:
    def __init__(self, yaxis):
        self.yaxis = yaxis

p = Person(64)

print(p.yaxis)

class Player:
    def __init__(self, yaxis):
        self.yaxis = yaxis,

p1 = Player(64)

print(p1.yaxis)

Output:

p = 64

p1 = (64,)

IDE Image Code Image

Console Code

Sofa44
  • 3
  • 1
  • 1
    Python didn't do this, YOU did this. You have a comma at the end of the line in `Player.__init__`. That makes it a tuple. Not sure how you could miss this. – Tim Roberts Jul 06 '21 at 03:33
  • 1
    You have a comma at the end of `self.yaxis = yaxis,` in `Player` class – Yash Jul 06 '21 at 03:36

1 Answers1

3

When you set the yaxis variable in the Player class, you have an extra comma at the end which causes python to automatically convert the variable to a tuple.

Dharman
  • 30,962
  • 25
  • 85
  • 135
patoc
  • 46
  • 2