Skip to content

Instantly share code, notes, and snippets.

@vrootic
Last active July 14, 2020 12:58
Show Gist options
  • Save vrootic/1286a4f65bfaa111eedac34c08f0b17e to your computer and use it in GitHub Desktop.
Save vrootic/1286a4f65bfaa111eedac34c08f0b17e to your computer and use it in GitHub Desktop.
class Point:
def __init__(self, x, y, name):
self.x = x
self.y = y
self.name = name
def get_coordinate(self):
return (self.x, self.y)
def set_name(self, name):
self.name = name
def get_name(self):
return self.name
# This function is not important.
def __str__(self):
return f'{self.name} ({self.x}, {self.y})'
# Example usage:
# Name (1, 0) as 'A'
point_A = Point(1, 0, 'A')
point_A.get_coordinate() # <- this line returns (1, 0)
point_A.get_name() # <- this line returns 'A'
# Create multiple points
# raw_coordinates = [(1, 0), (2, 4), (9, 100)]
# names = ['A', 'B', 'C']
points = []
for i, item in enumerate(raw_coordinates):
point = Point(item[0], item[1], names[i])
points.append(point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment