I just started learning Python, and I'm starting to get into Object-Oriented Programming. I wrote the following code which simply draws shapes using the turtle module, but I still don't quite understand the use of the "self" keyword:
import turtle
class Shape:
def __init__(self, sides, angle, color="white", thickness=1):
self.sides = sides
self.angle = angle
self.color = color
self.thickness = thickness
def draw(self):
for x in range(self.sides):
turtle.color(self.color)
turtle.pensize(self.thickness)
turtle.forward(100)
turtle.left(90)
if self.angle > 90:
turtle.right(self.angle - 90)
elif self.angle < 90:
turtle.left(90 - self.angle)
hexagon = Shape(6,120,"Red", 5)
hexagon.draw()