I have been coding in Java for years and my school here teaches Python, and I'm having a lot of trouble with it. My professor has asked us to create Connect4 in python and to start with these two methods:
def __init__( self, width, height ):
self.width = width
self.height = height
self.data = [] # this will be the board
for row in range( self.height ):
boardRow = []
for col in range( self.width ):
boardRow += [' ']
self.data += [boardRow]
def __repr__(self):
#print out rows & cols
s = '' # the string to return
for row in range( self.height ):
s += '|' # add the spacer character
for col in range( self.width ):
s += self.data[row][col] + '|'
s += '\n'
#print out separator
#your code here
# print out indices of each column
# using mod if greater than 9,
# for spacing issues
#your code here
return s # return it
I don't understand the self
argument, I've read lots about it and nothing seems to make sense to me. I was hoping someone could give me a little explanation of what self
is doing in this function, and why my professor is saying that the first function only two arguments are given but there are clearly three.
Any help/explanations would be greatly appreciated!
Here is where I got those functions.