首页 > 编程语言 >python3-bytes

python3-bytes

时间:2023-04-17 10:01:22浏览次数:34  
标签:__ errors encoding buffer object bytes python3

1、介绍

python3中,使用bytes类处理字节数据。

2、类

class bytes(object):
"""
    bytes(iterable_of_ints) -> bytes
    bytes(string, encoding[, errors]) -> bytes
    bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
    bytes(int) -> bytes object of size given by the parameter initialized with null bytes
    bytes() -> empty bytes object
"""
    def __init__(self, value=b'', encoding=None, errors='strict'):
        pass

3、字面量初始化

a = b'abc\xe6\x97\xb6\xe9\x97\xb4'

4、类初始化

    bytes(iterable_of_ints) -> bytes
    bytes(string, encoding[, errors]) -> bytes
    bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
    bytes(int) -> bytes object of size given by the parameter initialized with null bytes
    bytes() -> empty bytes object

5、属性

6、方法

提供了一系列的字节层面的操作方法

(1)split

split(sep, maxsplit)
  • sep,分割参数,类型必须是bytes。作用和str的split类似
  • maxsplit,int类型,最大分割次数。默认为0表示分割所有
  • 返回list类型,如果未匹配,则list中有且只有一个元素,即待分割样本

(2)index

index(sub, start, end)

(3)count

count(sub, start, end)

(4)strip

strip(__bytes)

标签:__,errors,encoding,buffer,object,bytes,python3
From: https://www.cnblogs.com/wd404/p/17324870.html

相关文章

  • python3-type
    1、介绍type本身是内建模块中的一个类,其主要作用是用于判断变量的数据类型。2、类classtype(object):def__init__(cls,what,bases=None,dict=None):"""type(object_or_name,bases,dict)type(object)->theobject'stypetype......
  • python3-len
    1、介绍python3中,可以使用函数len获取容器对象的长度,比如str字符串、list列表等。2、函数deflen(*args,**kwargs):pass返回类型为int,如果长度为0,则就返回0不能对非容器变量使用,会报错,比如int、None值3、示例#不能对非容器变量使用,会报错#print(len(123))pri......
  • 部署Python3
    1、安装编译工具yum-ygroupinstall"Developmenttools"yum-yinstallzlib-develbzip2-developenssl-develncurses-develsqlite-develreadline-develtk-develgdbm-develdb4-devellibpcap-develxz-develyuminstalllibffi-devel2、下载软件包并解压wgethttps://ww......
  • Python3基本请求库-urllib
    urlliburlopen一个基本请求fromurllibimportrequest,parsedefApi():#禁用证书验证ssl._create_default_https_context=ssl._create_unverified_contextresponse=request.urlopen('https://www.baidu.com/')print(response.read().decode(�......
  • python3正则-表达式
    1、介绍这里整理了表达式,即pattern参数的语法。其本质是一个str类型。2、开始和结尾(1)^^匹配字符串的开头(2)$$匹配字符串的末尾(3)整体匹配同时使用^和$3、匹配次数(1)贪婪匹配和非贪婪匹配模式贪婪匹配,在允许的范围内尽可能多的匹配表达式次数。比如*、+、{n,m}等......
  • python3正则-修饰符flags
    1、介绍在re模块的函数中,多数允许设置修饰符flags参数,其用于对匹配做优化和个性设置。2、修饰符修饰符实质上是int参数类型,可以直接指定int类型,也可以通过re调用变量名称指定。修饰符描述re.I使匹配对大小写不敏感re.L做本地化识别(locale-aware)匹配re.M多行......
  • python3正则-Match类
    1、介绍re.match、re.fullmatch和re.search这三个函数,如果存在匹配,其返回pattern初次匹配的结果,类型就为re.Match。2、类和初始化3、方法pattern="(ab)c"result=re.match(pattern=pattern,string="abcdef")print(result)(1)start获取pattern整体匹配的开始索引,返回类......
  • python3正则-编译和其他
    1、介绍将作为pattern参数的str类型,编译返回Pattern类型,方便后续调用,提高效率。re模块下存在多个函数,可以进行编译,返回类型是Pattern。Pattern类具有和re正则匹配函数类似的方法,当然在参数上略有不同,比如是将待匹配文本作为Pattern类的参数。2、compile函数pattern=re.comp......
  • python3时间
    1、介绍time模块是python的内部模块。2、函数#返回float类型,1670592065.0852547形式#print(time.time())#print(type(time.time()))#休眠,单位秒#time.sleep(5)#print(123)#返回int类型,1670592289035206400形式#print(time.time_ns())#print(type(time.time_......
  • python3正则-替换和切割函数
    1、介绍这里整理sub、subn和split三个函数的使用。2、sub函数sub(pattern,repl,string,count=0,flags=0)pattern,正则表达式repl,替换文本string,待处理字符串count,表示替换的最大次数。默认为0表示全部替换flags,标志,处理模式作用是在flags代表的模式下,匹配strings指......