设为首页 收藏本站
查看: 711|回复: 0

[经验分享] python内置函数2-bytearray()

[复制链接]

尚未签到

发表于 2018-8-15 11:04:45 | 显示全部楼层 |阅读模式
  Help on>  class bytearray(object)
  |  bytearray(iterable_of_ints) -> bytearray.
  |  bytearray(string, encoding[, errors]) -> bytearray.
  |  bytearray(bytes_or_bytearray) -> mutable copy of bytes_or_bytearray.
  |  bytearray(memory_view) -> bytearray.
  |
  |  Construct an mutable bytearray object from:
  |    - an iterable yielding integers in range(256)
  |    - a text string encoded using the specified encoding
  |    - a bytes or a bytearray object
  |    - any object implementing the buffer API.
  |
  |  bytearray(int) -> bytearray.
  |
  |  Construct a zero-initialized bytearray of the given length.
  |
  |  Methods defined here:
  |
  |  __add__(...)
  |      x.__add__(y) <==> x+y
  |
  |  __alloc__(...)
  |      B.__alloc__() -> int
  |
  |      Returns the number of bytes actually allocated.
  |
  |  __contains__(...)
  |      x.__contains__(y) <==> y in x
  |
  |  __delitem__(...)
  |      x.__delitem__(y) <==> del x[y]
  |
  |  __eq__(...)
  |      x.__eq__(y) <==> x==y
  |
  |  __ge__(...)
  |      x.__ge__(y) <==> x>=y
  |
  |  __getattribute__(...)
  |      x.__getattribute__('name') <==> x.name
  |
  |  __getitem__(...)
  |      x.__getitem__(y) <==> x[y]
  |
  |  __gt__(...)
  |      x.__gt__(y) <==> x>y
  |
  |  __iadd__(...)
  |      x.__iadd__(y) <==> x+=y
  |
  |  __imul__(...)
  |      x.__imul__(y) <==> x*=y
  |
  |  __init__(...)
  |      x.__init__(...) initializes x; see help(type(x)) for signature
  |
  |  __iter__(...)
  |      x.__iter__() <==> iter(x)
  |
  |  __le__(...)
  |      x.__le__(y) <==> x<=y
  |
  |  __len__(...)
  |      x.__len__() <==> len(x)
  |
  |  __lt__(...)
  |      x.__lt__(y) <==> x<y
  |
  |  __mul__(...)
  |      x.__mul__(n) <==> x*n
  |
  |  __ne__(...)
  |      x.__ne__(y) <==> x!=y
  |
  |  __reduce__(...)
  |      Return state information for pickling.
  |
  |  __repr__(...)
  |      x.__repr__() <==> repr(x)
  |
  |  __rmul__(...)
  |      x.__rmul__(n) <==> n*x
  |
  |  __setitem__(...)
  |      x.__setitem__(i, y) <==> x=y
  |
  |  __sizeof__(...)
  |      B.__sizeof__() -> int
  |

  |      Returns the>  |
  |  __str__(...)
  |      x.__str__() <==> str(x)
  |
  |  append(...)
  |      B.append(int) -> None
  |
  |      Append a single item to the end of B.
  |
  |  capitalize(...)
  |      B.capitalize() -> copy of B
  |
  |      Return a copy of B with only its first character capitalized (ASCII)
  |      and the rest lower-cased.
  |
  |  center(...)
  |      B.center(width[, fillchar]) -> copy of B
  |

  |      Return B centered in a string of length>  |      done using the specified fill character (default is a space).
  |
  |  count(...)
  |      B.count(sub [,start [,end]]) -> int
  |
  |      Return the number of non-overlapping occurrences of subsection sub in
  |      bytes B[start:end].  Optional arguments start and end are interpreted
  |      as in slice notation.
  |
  |  decode(...)
  |      B.decode([encoding[, errors]]) -> unicode object.
  |
  |      Decodes B using the codec registered for encoding. encoding defaults
  |      to the default encoding. errors may be given to set a different error
  |      handling scheme.  Default is 'strict' meaning that encoding errors raise
  |      a UnicodeDecodeError.  Other possible values are 'ignore' and 'replace'
  |      as well as any other name registered with codecs.register_error that is
  |      able to handle UnicodeDecodeErrors.
  |
  |  endswith(...)
  |      B.endswith(suffix [,start [,end]]) -> bool
  |
  |      Return True if B ends with the specified suffix, False otherwise.
  |      With optional start, test B beginning at that position.
  |      With optional end, stop comparing B at that position.
  |      suffix can also be a tuple of strings to try.
  |
  |  expandtabs(...)
  |      B.expandtabs([tabsize]) -> copy of B
  |
  |      Return a copy of B where all tab characters are expanded using spaces.

  |      If tabsize is not given, a tab>  |
  |  extend(...)
  |      B.extend(iterable int) -> None
  |
  |      Append all the elements from the iterator or sequence to the
  |      end of B.
  |
  |  find(...)
  |      B.find(sub [,start [,end]]) -> int
  |
  |      Return the lowest index in B where subsection sub is found,
  |      such that sub is contained within B[start,end].  Optional
  |      arguments start and end are interpreted as in slice notation.
  |
  |      Return -1 on failure.
  |
  |  fromhex(...)
  |      bytearray.fromhex(string) -> bytearray
  |
  |      Create a bytearray object from a string of hexadecimal numbers.
  |      Spaces between two numbers are accepted.
  |      Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\xb9\x01\xef').
  |
  |  index(...)
  |      B.index(sub [,start [,end]]) -> int
  |
  |      Like B.find() but raise ValueError when the subsection is not found.
  |
  |  insert(...)
  |      B.insert(index, int) -> None
  |
  |      Insert a single item into the bytearray before the given index.
  |
  |  isalnum(...)
  |      B.isalnum() -> bool
  |
  |      Return True if all characters in B are alphanumeric
  |      and there is at least one character in B, False otherwise.
  |
  |  isalpha(...)
  |      B.isalpha() -> bool
  |
  |      Return True if all characters in B are alphabetic
  |      and there is at least one character in B, False otherwise.
  |
  |  isdigit(...)
  |      B.isdigit() -> bool
  |
  |      Return True if all characters in B are digits
  |      and there is at least one character in B, False otherwise.
  |
  |  islower(...)
  |      B.islower() -> bool
  |
  |      Return True if all cased characters in B are lowercase and there is
  |      at least one cased character in B, False otherwise.
  |
  |  isspace(...)
  |      B.isspace() -> bool
  |
  |      Return True if all characters in B are whitespace
  |      and there is at least one character in B, False otherwise.
  |
  |  istitle(...)
  |      B.istitle() -> bool
  |

  |      Return True if B is a>  |      character in B, i.e. uppercase characters may only follow uncased
  |      characters and lowercase characters only cased ones. Return False
  |      otherwise.
  |
  |  isupper(...)
  |      B.isupper() -> bool
  |
  |      Return True if all cased characters in B are uppercase and there is
  |      at least one cased character in B, False otherwise.
  |
  |  join(...)
  |      B.join(iterable_of_bytes) -> bytes
  |
  |      Concatenates any number of bytearray objects, with B in between each pair.
  |
  |  ljust(...)
  |      B.ljust(width[, fillchar]) -> copy of B
  |

  |      Return B left justified in a string of length>  |      done using the specified fill character (default is a space).
  |
  |  lower(...)
  |      B.lower() -> copy of B
  |
  |      Return a copy of B with all ASCII characters converted to lowercase.
  |
  |  lstrip(...)
  |      B.lstrip([bytes]) -> bytearray
  |
  |      Strip leading bytes contained in the argument.
  |      If the argument is omitted, strip leading ASCII whitespace.
  |
  |  partition(...)
  |      B.partition(sep) -> (head, sep, tail)
  |
  |      Searches for the separator sep in B, and returns the part before it,
  |      the separator itself, and the part after it.  If the separator is not
  |      found, returns B and two empty bytearray objects.
  |
  |  pop(...)
  |      B.pop([index]) -> int
  |
  |      Remove and return a single item from B. If no index
  |      argument is given, will pop the last value.
  |
  |  remove(...)
  |      B.remove(int) -> None
  |
  |      Remove the first occurance of a value in B.
  |
  |  replace(...)
  |      B.replace(old, new[, count]) -> bytes
  |
  |      Return a copy of B with all occurrences of subsection
  |      old replaced by new.  If the optional argument count is
  |      given, only the first count occurrences are replaced.
  |
  |  reverse(...)
  |      B.reverse() -> None
  |
  |      Reverse the order of the values in B in place.
  |
  |  rfind(...)
  |      B.rfind(sub [,start [,end]]) -> int
  |
  |      Return the highest index in B where subsection sub is found,
  |      such that sub is contained within B[start,end].  Optional
  |      arguments start and end are interpreted as in slice notation.
  |
  |      Return -1 on failure.
  |
  |  rindex(...)
  |      B.rindex(sub [,start [,end]]) -> int
  |
  |      Like B.rfind() but raise ValueError when the subsection is not found.
  |
  |  rjust(...)
  |      B.rjust(width[, fillchar]) -> copy of B
  |

  |      Return B right justified in a string of length>  |      done using the specified fill character (default is a space)
  |
  |  rpartition(...)
  |      B.rpartition(sep) -> (head, sep, tail)
  |
  |      Searches for the separator sep in B, starting at the end of B,
  |      and returns the part before it, the separator itself, and the
  |      part after it.  If the separator is not found, returns two empty
  |      bytearray objects and B.
  |
  |  rsplit(...)
  |      B.rsplit(sep[, maxsplit]) -> list of bytearray
  |
  |      Return a list of the sections in B, using sep as the delimiter,
  |      starting at the end of B and working to the front.
  |      If sep is not given, B is split on ASCII whitespace characters
  |      (space, tab, return, newline, formfeed, vertical tab).
  |      If maxsplit is given, at most maxsplit splits are done.
  |
  |  rstrip(...)
  |      B.rstrip([bytes]) -> bytearray
  |
  |      Strip trailing bytes contained in the argument.
  |      If the argument is omitted, strip trailing ASCII whitespace.
  |
  |  split(...)
  |      B.split([sep[, maxsplit]]) -> list of bytearray
  |
  |      Return a list of the sections in B, using sep as the delimiter.
  |      If sep is not given, B is split on ASCII whitespace characters
  |      (space, tab, return, newline, formfeed, vertical tab).
  |      If maxsplit is given, at most maxsplit splits are done.
  |
  |  splitlines(...)
  |      B.splitlines([keepends]) -> list of lines
  |
  |      Return a list of the lines in B, breaking at line boundaries.
  |      Line breaks are not included in the resulting list unless keepends
  |      is given and true.
  |
  |  startswith(...)
  |      B.startswith(prefix [,start [,end]]) -> bool
  |
  |      Return True if B starts with the specified prefix, False otherwise.
  |      With optional start, test B beginning at that position.
  |      With optional end, stop comparing B at that position.
  |      prefix can also be a tuple of strings to try.
  |
  |  strip(...)
  |      B.strip([bytes]) -> bytearray
  |
  |      Strip leading and trailing bytes contained in the argument.
  |      If the argument is omitted, strip ASCII whitespace.
  |
  |  swapcase(...)
  |      B.swapcase() -> copy of B
  |
  |      Return a copy of B with uppercase ASCII characters converted
  |      to lowercase ASCII and vice versa.
  |
  |  title(...)
  |      B.title() -> copy of B
  |

  |      Return a>  |      characters, all remaining cased characters have lowercase.
  |
  |  translate(...)
  |      B.translate(table[, deletechars]) -> bytearray
  |
  |      Return a copy of B, where all characters occurring in the
  |      optional argument deletechars are removed, and the remaining
  |      characters have been mapped through the given translation
  |      table, which must be a bytes object of length 256.
  |
  |  upper(...)
  |      B.upper() -> copy of B
  |
  |      Return a copy of B with all ASCII characters converted to uppercase.
  |
  |  zfill(...)
  |      B.zfill(width) -> copy of B
  |
  |      Pad a numeric string B with zeros on the left, to fill a field

  |      of the specified>  |
  |  ----------------------------------------------------------------------
  |  Data and other attributes defined here:
  |
  |  __new__ = <built-in method __new__ of type object>
  |      T.__new__(S, ...) -> a new object with type S, a subtype of T
  class bytearray([source[, encoding[, errors]]])

  Return a new array of bytes. The bytearray>  The optional source parameter can be used to initialize the array in a few different ways:
  If it is unicode, you must also give the encoding (and optionally, errors) parameters; bytearray() then converts the unicode to bytes using unicode.encode().

  If it is an integer, the array will have that>  If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array.
  If it is an iterable, it must be an iterable of integers in the range 0 <= x < 256, which are used as the initial contents of the array.

  Without an argument, an array of>  中文说明:
  bytearray([source [, encoding [, errors]]])返回一个byte数组。Bytearray类型是一个可变的序列,并且序列中的元素的取值范围为 [0 ,255]。
  参数source:
  如果source为整数,则返回一个长度为source的初始化数组;
  如果source为字符串,则按照指定的encoding将字符串转换为字节序列;
  如果source为可迭代类型,则元素必须为[0 ,255]中的整数;
  如果source为与buffer接口一致的对象,则此对象也可以被用于初始化bytearray.。
  >>> a=bytearray(3)
  >>> a
  bytearray(b'\x00\x00\x00')
  >>> a[0]
  0
  >>> a[1]
  0
  >>> a[2]
  0
  >>> b=bytearray('abc')
  >>> b
  bytearray(b'abc')
  >>> b[0]
  97
  >>> b[1]
  98
  >>> b[2]
  99
  >>> c=bytearray([1,2,3])
  >>> c
  bytearray(b'\x01\x02\x03')
  >>> c[0]
  1
  >>> c[1]
  2
  >>> c[2]
  3
  >>> d=bytearray(buffer('abc'))
  >>> d
  bytearray(b'abc')
  >>> d[0]
  97
  >>> d[1]
  98
  >>> d[2]
  99

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-552133-1-1.html 上篇帖子: [硕.Love Python] BinomialHeap(B堆 & 二项堆) 下篇帖子: python内置函数2-callable()
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表