Skip to content

Commit 388496f

Browse files
authored
Merge pull request #3447 from DickerDackel/vector-to-tuple
2 parents 426d532 + b3d135c commit 388496f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

docs/reST/ref/math.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,32 @@ subscripts
3535
v.y == v[1]
3636
v.z == v[2]
3737

38-
Multiple coordinates can be set using slices or swizzling
38+
Multiple coordinates can be set and retrieved using slices or swizzling.
3939

4040
::
4141

4242
v = pygame.Vector2()
4343
v.xy = 1, 2
4444
v[:] = 1, 2
45+
print(v) # Vector2(1, 2)
46+
print(v.x) # 1.0
47+
print(v.y) # 2.0
48+
print(v.xy) # Vector2(1, 2)
49+
print(v.yx) # Vector2(2, 1)
50+
print(v.xyyx) # (1.0, 2.0, 2.0, 1.0)
51+
52+
Note above, that swizzling with 2 components will return a Vector2 instance
53+
again, while more than 2 components will result in a tuple. But since vectors
54+
support the iterator protocol, they can be unpacked, or converted to lists or
55+
tuples.
56+
57+
::
58+
59+
v = Vector2(1, 2)
60+
print(*v) # 1.0 2.0
61+
print(tuple(v)) # (1.0, 2.0)
62+
print(tuple(v.yx)) # (2.0, 1.0)
63+
4564

4665
.. versionaddedold:: 1.9.2pre
4766
.. versionchangedold:: 1.9.4 Removed experimental notice.

0 commit comments

Comments
 (0)