iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python内置函数2-bytearra
  • 398
分享到

python内置函数2-bytearra

函数pythonbytearra 2023-01-31 02:01:31 398人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

Help on class bytearray in module __builtin__:class bytearray(object) |  bytearray(iterable_of_ints) -> bytearray. |

Help on class bytearray in module __builtin__:


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[i]=y

 |  

 |  __sizeof__(...)

 |      B.__sizeof__() -> int

 |       

 |      Returns the size of B in memory, in bytes

 |  

 |  __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 width.  Padding is

 |      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 size of 8 characters is assumed.

 |  

 |  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 titlecased string and there is at least one

 |      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 width. Padding is

 |      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 width. Padding is

 |      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 titlecased version of B, i.e. ASCII Words start with uppercase

 |      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 width.  B is never truncated.

 |  

 |  ----------------------------------------------------------------------

 |  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 class is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the str type has, see String Methods.


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 size and will be initialized with null bytes.

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 size 0 is created.


中文说明:

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


--结束END--

本文标题: python内置函数2-bytearra

本文链接: https://www.lsjlt.com/news/186813.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • python内置函数2-bytearra
    Help on class bytearray in module __builtin__:class bytearray(object) |  bytearray(iterable_of_ints) -> bytearray. | ...
    99+
    2023-01-31
    函数 python bytearra
  • Python 内置函数详解 (2) 逻辑运算
    近期在外旅游,本篇是出发编辑的,准备定时发布用,不完整,旅游回来后再补充。 Python 内置函数 Python3.11共有75个内置函数,其来历和分类请参考:Python 新版本有75个内置函数,你不会不知道吧_Hann Yang的博客...
    99+
    2023-09-20
    python
  • day 16 - 2 内置函数(二)练习
    内置函数(二)练习 1、用 map 来处理字符串列表,把列表中所有人都变成 sb,比方 alex_sbname=['alex','wupeiqi','yuanhao','nezha']   name=['alex','wupeiqi',...
    99+
    2023-01-30
    函数 day
  • python 函数(2)
    一、内容回顾 1.面试题相关: 1.py2和py3的区别 2.运算符的计算 :3 or 9 and 8 3.字符串的反转 4.is和==的区别 5.v1 = (1) v2 = 1 v3 = (1,)有什么区别 v1 、v2都是数...
    99+
    2023-01-31
    函数 python
  • python内置函数
    什么是内置函数 就是python给你提供的,拿来直接用的函数, 比如print 和 input等等. 截止到python版本3.6.2 python一共提供了68个内置函数. 他们就是python直接提供给我们的,有一些我们已经见过了. ...
    99+
    2023-01-30
    函数 python
  • python 内置函数
    python内置了一系列的常用函数,以便于我们使用python。基本的数据操作基本都是一些数学运算(当然除了加减乘除)、逻辑操作、集合操作、基本IO操作,然后就是对于语言自身的反射操作,还有就是字符串操作。官方文档:https://docs...
    99+
    2023-01-30
    函数 python
  • python 之 函数 2
    5.36 命名关键字 什么是命名关键字参数? 格式:在*后面参数都是命名关键字参数 特点: 1 必须被传值 2 约束函数的调用者必须按照key=value的形式传值 3 约束函数的调用者必须用我们指定的key名 def foo(x,y,...
    99+
    2023-01-31
    函数 python
  • Python-2 eval函数
    x = 1result = "x+1"result = eval(result)print(result)》》2 Python3中字符串不能计算结果,eval函数将字符串当成有效Python表达式来求值,并返回计算结果。 与之对应的repr...
    99+
    2023-01-31
    函数 Python eval
  • python内置函数1
    1.r=compile(s,"<string>","exec")  compile()将字符串编译成python代码2.exec(r)  执行python代码3.eval("8*6") eval("")里面只能执行表达式,执行e...
    99+
    2023-01-31
    函数 python
  • Python的内置函数
    1.什么是内置函数   就是python给你提供的. 拿来直接⽤的函数, 比如print., input等等. 截止到python版本3.6 python一共提供了68个内置函数. 他们就是python直接提供给我们的 Makedo...
    99+
    2023-01-31
    函数 Python
  • Python之内置函数
    ''' 内置函数 :     作用域相关(2) :         locals : 返回当前局部作用域内的所有内容         globals : 返回全局作用域内的所有内容     基础数据类型相关(38) :         和数...
    99+
    2023-01-31
    函数 Python
  • Python系列-python内置函数
    本文转载自:http://www.javaxxz.com/thread-359303-1-1.htmlabs(x)返回数字的绝对值,参数可以是整数、也可以是浮点数。如果是复数,则返回它的大小all(iterable)对参数中的所有元素进行迭...
    99+
    2023-01-31
    函数 系列 Python
  • Python内置函数详谈
    这种图皆取自python.org,列出了python3.10中的内置函数。 但是,这些真的都是函数吗? 我们来测试一下: import types import inspect...
    99+
    2024-04-02
  • python内置函数3-dir()
    Help on built-in function dir in module __builtin__:dir(...)    dir([object]) -> list of strings        If called wit...
    99+
    2023-01-31
    函数 python dir
  • python内置函数3-complex(
    Help on class complex in module __builtin__:class complex(object) |  complex(real[, imag]) -> complex number |   |  C...
    99+
    2023-01-31
    函数 python complex
  • python 之 python3内置函数
    一. 简介   python内置了一系列的常用函数,以便于我们使用,python英文官方文档详细说明:点击查看, 为了方便查看,将内置函数的总结记录下来。   二. 使用说明...
    99+
    2024-04-02
  • python内置函数3-compile(
    Help on built-in function compile in module __builtin__:compile(...)    compile(source, filename, mode[, flags[, dont_in...
    99+
    2023-01-31
    函数 python compile
  • python-常用内置函数
    1.其他   - len / open / id / range / type 2.输入输出   - print / input  3.强制转换   - dict / list / tuple / int / str / bool / ...
    99+
    2023-01-31
    函数 常用 python
  • python内置函数3-delattr(
    Help on built-in function delattr in module __builtin__:delattr(...)    delattr(object, name)        Delete a named attr...
    99+
    2023-01-31
    函数 python delattr
  • zero python.3 内置函数
    内置函数...
    99+
    2023-01-31
    函数 python
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作