Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(267615)

Side by Side Diff: Doc/library/stdtypes.rst

Issue 13411: Hashable memoryviews
Patch Set: Created 7 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Include/memoryobject.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 .. XXX: reference/datamodel and this have quite a few overlaps! 1 .. XXX: reference/datamodel and this have quite a few overlaps!
2 2
3 3
4 .. _bltin-types: 4 .. _bltin-types:
5 5
6 ************** 6 **************
7 Built-in Types 7 Built-in Types
8 ************** 8 **************
9 9
10 The following sections describe the standard types that are built into the 10 The following sections describe the standard types that are built into the
(...skipping 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 bytearray(b'zbcefg') 2393 bytearray(b'zbcefg')
2394 >>> v[1:4] = b'123' 2394 >>> v[1:4] = b'123'
2395 >>> data 2395 >>> data
2396 bytearray(b'a123fg') 2396 bytearray(b'a123fg')
2397 >>> v[2] = b'spam' 2397 >>> v[2] = b'spam'
2398 Traceback (most recent call last): 2398 Traceback (most recent call last):
2399 File "<stdin>", line 1, in <module> 2399 File "<stdin>", line 1, in <module>
2400 ValueError: cannot modify size of memoryview object 2400 ValueError: cannot modify size of memoryview object
2401 2401
2402 Notice how the size of the memoryview object cannot be changed. 2402 Notice how the size of the memoryview object cannot be changed.
2403
2404 Memoryviews of hashable (read-only) types are also hashable and their
2405 hash value matches the corresponding bytes object::
2406
2407 >>> v = memoryview(b'abcefg')
2408 >>> hash(v) == hash(b'abcefg')
2409 True
2410 >>> hash(v[2:4]) == hash(b'ce')
2411 True
2412
2413 .. versionchanged:: 3.3
2414 Memoryview objects are now hashable.
2415
2403 2416
2404 :class:`memoryview` has several methods: 2417 :class:`memoryview` has several methods:
2405 2418
2406 .. method:: tobytes() 2419 .. method:: tobytes()
2407 2420
2408 Return the data in the buffer as a bytestring. This is equivalent to 2421 Return the data in the buffer as a bytestring. This is equivalent to
2409 calling the :class:`bytes` constructor on the memoryview. :: 2422 calling the :class:`bytes` constructor on the memoryview. ::
2410 2423
2411 >>> m = memoryview(b"abc") 2424 >>> m = memoryview(b"abc")
2412 >>> m.tobytes() 2425 >>> m.tobytes()
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 .. [2] As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0] ``, and 2852 .. [2] As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0] ``, and
2840 similarly for tuples. 2853 similarly for tuples.
2841 2854
2842 .. [3] They must have since the parser can't tell the type of the operands. 2855 .. [3] They must have since the parser can't tell the type of the operands.
2843 2856
2844 .. [4] Cased characters are those with general category property being one of 2857 .. [4] Cased characters are those with general category property being one of
2845 "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt" (Letter, titlecas e). 2858 "Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt" (Letter, titlecas e).
2846 2859
2847 .. [5] To format only a tuple you should therefore provide a singleton tuple who se only 2860 .. [5] To format only a tuple you should therefore provide a singleton tuple who se only
2848 element is the tuple to be formatted. 2861 element is the tuple to be formatted.
OLDNEW
« no previous file with comments | « no previous file | Include/memoryobject.h » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+