Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
18da8f06
Kaydet (Commit)
18da8f06
authored
Tem 01, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#3220: improve bytes docs a bit.
üst
07a1f94f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
stdtypes.rst
Doc/library/stdtypes.rst
+13
-10
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
18da8f06
...
@@ -512,17 +512,21 @@ string literals. In addition to the functionality described here, there are
...
@@ -512,17 +512,21 @@ string literals. In addition to the functionality described here, there are
also string-specific methods described in the :ref:`string-methods` section.
also string-specific methods described in the :ref:`string-methods` section.
Bytes and bytearray objects contain single bytes -- the former is immutable
Bytes and bytearray objects contain single bytes -- the former is immutable
while the latter is a mutable sequence. Bytes objects can be constructed from
while the latter is a mutable sequence. Bytes objects can be constructed the
literals too; use a ``b`` prefix with normal string syntax: ``b'xyzzy'``. To
constructor, :func:`bytes`, and from literals; use a ``b`` prefix with normal
construct byte arrays, use the :func:`bytearray` function.
string syntax: ``b'xyzzy'``. To construct byte arrays, use the
:func:`bytearray` function.
.. warning::
.. warning::
While string objects are sequences of characters (represented by strings of
While string objects are sequences of characters (represented by strings of
length 1), bytes and bytearray objects are sequences of *integers* (between 0
length 1), bytes and bytearray objects are sequences of *integers* (between 0
and 255), representing the ASCII value of single bytes. That means that for
and 255), representing the ASCII value of single bytes. That means that for
a bytes or bytearray object *b*, ``b[0]`` will be an integer, while ``b[0:1]``
a bytes or bytearray object *b*, ``b[0]`` will be an integer, while
will be a bytes or bytearray object of length 1.
``b[0:1]`` will be a bytes or bytearray object of length 1. The
representation of bytes objects uses the literal format (``b'...'``) since it
is generally more useful than e.g. ``bytes([50, 19, 100])``. You can always
convert a bytes object into a list of integers using ``list(b)``.
Also, while in previous Python versions, byte strings and Unicode strings
Also, while in previous Python versions, byte strings and Unicode strings
could be exchanged for each other rather freely (barring encoding issues),
could be exchanged for each other rather freely (barring encoding issues),
...
@@ -1413,12 +1417,11 @@ Wherever one of these methods needs to interpret the bytes as characters
...
@@ -1413,12 +1417,11 @@ Wherever one of these methods needs to interpret the bytes as characters
The bytes and bytearray types have an additional class method:
The bytes and bytearray types have an additional class method:
.. method:: bytes.fromhex(string)
.. method:: bytes.fromhex(string)
bytearray.fromhex(string)
This :class:`bytes` class method returns a bytes object, decoding the given
This :class:`bytes` class method returns a bytes or bytearray object,
string object. The string must contain two hexadecimal digits per byte, spaces
decoding the given string object. The string must contain two hexadecimal
are ignored.
digits per byte, spaces are ignored.
Example::
>>> bytes.fromhex('f0 f1f2 ')
>>> bytes.fromhex('f0 f1f2 ')
b'\xf0\xf1\xf2'
b'\xf0\xf1\xf2'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment