Skip to content

Commit 8c7e963

Browse files
authored
Create pretty.py
1 parent 7b4b99f commit 8c7e963

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

python/pretty.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Vector:
2+
def __init__(self, x, y, z):
3+
self.x = x
4+
self.y = y
5+
self.z = z
6+
7+
def __str__(self):
8+
fields = [
9+
("x", self.x),
10+
("y", self.y),
11+
("z", self.z)
12+
]
13+
14+
return "Vector { " + ", ".join(["%s=%s" % (k, v) for (k, v) in fields]) + " }"
15+
16+
vec = Vector(1, 2, 3)
17+
18+
print(vec)
19+
print("{0}".format(42))
20+
print(["%s=%s" % (42, 21) for (k, v) in [("a", 1), ("b", 2), ("c", 3)]])

0 commit comments

Comments
 (0)