Skip to content

Commit ae6d9a8

Browse files
committed
first test of first example
1 parent 82d83ac commit ae6d9a8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

examples/vector0.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
>>> v1 = Vector([1, 2])
55
>>> v1
66
Vector([1.0, 2.0])
7+
>>> format(v1)
8+
'(1.0, 2.0)'
9+
>>> format(v1, '.2f')
10+
'(1.00, 2.00)'
11+
>>> format(v1, '.3e')
12+
'(1.000e+00, 2.000e+00)
13+
714
815
'''
916

@@ -31,4 +38,7 @@ def __eq__(self, other):
3138
all(a == b for a, b in zip(self, other)))
3239

3340
def __repr__(self):
34-
return 'Vector({})'.format(list(self._components))
41+
return 'Vector({})'.format(list(self))
42+
43+
def __format__(self, format_spec):
44+
return repr(tuple(self))

0 commit comments

Comments
 (0)