forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint.py
More file actions
48 lines (35 loc) · 980 Bytes
/
Copy pathpoint.py
File metadata and controls
48 lines (35 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from dataclasses import dataclass
# Point with slots
# class Point:
# __slots__ = ("x", "y")
# def __init__(self, x, y):
# self.x = x
# self.y = y
# Regular class
# class ThreeDPoint:
# def __init__(self, x, y, z):
# self.x = x
# self.y = y
# self.z = z
# def __iter__(self):
# yield from (self.x, self.y, self.z)
# @classmethod
# def from_sequence(cls, sequence):
# return cls(*sequence)
# @staticmethod
# def show_intro_message(name):
# print(f"Hey {name}! This is your 3D Point!")
# def __repr__(self):
# return f"{type(self).__name__}({self.x}, {self.y}, {self.z})"
# Dataclass
@dataclass
class ThreeDPoint:
x: int | float
y: int | float
z: int | float
@classmethod
def from_sequence(cls, sequence):
return cls(*sequence)
@staticmethod
def show_intro_message(name):
print(f"Hey {name}! This is your 3D Point!")