当前位置: 首页 > news >正文

莆田有哪几家做网站设计百度竞价推广出价技巧

莆田有哪几家做网站设计,百度竞价推广出价技巧,北京网站建设怎么样天,网上作业网站怎么做的在Python中,bytearray 是一个可变序列,用于表示一个字节数组。与不可变的 bytes 类型相比,bytearray 允许你修改其内容。你可以通过索引来访问和修改 bytearray 中的元素,也可以添加或删除元素。 使用 bytearray 的一些示例&…

在Python中,bytearray 是一个可变序列,用于表示一个字节数组。与不可变的 bytes 类型相比,bytearray 允许你修改其内容。你可以通过索引来访问和修改 bytearray 中的元素,也可以添加或删除元素。

使用 bytearray 的一些示例:

# 创建一个空的 bytearrayba = bytearray()print(ba) # 输出: bytearray(b'')# 创建一个包含初始值的 bytearrayba = bytearray([0x11, 0x22, 0x33])print(ba) # 输出: bytearray(b'\x11\x22\x33')# 访问 bytearray 中的元素print(ba[0]) # 输出: 17(0x11 的十进制表示)# 修改 bytearray 中的元素ba[1] = 0x44print(ba) # 输出: bytearray(b'\x11D\x33'),其中 'D' 是 0x44 的 ASCII 字符# 添加元素到 bytearray 的末尾ba.append(0x55)print(ba) # 输出: bytearray(b'\x11D\x33U'),其中 'U' 是 0x55 的 ASCII 字符# 从 bytearray 中删除元素del ba[2]print(ba) # 输出: bytearray(b'\x11D\x55')# 将 bytes 转换为 bytearrayb = b'\x01\x02\x03'ba = bytearray(b)print(ba) # 输出: bytearray(b'\x01\x02\x03')# 将 bytearray 转换为 bytesb = bytes(ba)print(b) # 输出: b'\x01\x02\x03'

在上面的示例中,你可以看到如何使用 bytearray 来存储和操作字节序列。这对于需要频繁修改字节数据的场景特别有用,因为 bytes 类型是不可变的,每次修改都需要创建一个新的 bytes 对象。而 bytearray 允许你原地修改数据,从而提高性能。

数组的长度:

# 创建一个bytearray  
app_buf = bytearray([0x11, 0x22, 0x33])  # 输出bytearray的长度  
print(len(app_buf))  # 输出: 3

数组打印

注意:如果数组里的内容为 字符直接用print 打印就会直接打印成字符!例如

ba[1] = 0x44   print(ba) # 输出: bytearray(b'\x11D\x33'),其中 'D' 是 0x44 的 ASCII 字符

十六进制方式打印数组

要以十六进制的方式打印bytearray中的每个字节,你可以使用列表推导式(list comprehension)结合format函数或f-string(格式化字符串字面量)来格式化每个字节。以下是一些示例:

使用循环和直接打印


app1_buf = bytearray([0x11,0x23,0x63])
for byte in app1_buf:print(f"{byte:02X}", end=' ')

使用列表推导式和format函数

app_buf = bytearray([0x11, 0x22, 0x33]) 
hex_values = ['{:02X}'.format(byte) for byte in app_buf] 
print(' '.join(hex_values)) # 输出: 11 22 33

使用列表推导式和f-string(Python 3.6+)

app_buf = bytearray([0x11, 0x22, 0x33])hex_values = [f'{byte:02X}' for byte in app_buf]print(' '.join(hex_values)) # 输出: 11 22 33

在这两个示例中,我们都创建了一个列表推导式来遍历bytearray中的每个字节,并使用format函数或f-string将其格式化为两位的十六进制字符串。然后,我们使用join方法将这些字符串连接成一个用空格分隔的字符串,并打印出来。

十进制打印数组

如果你想要以十进制的方式打印bytearray中的每个字节,你可以直接遍历bytearray并打印每个字节的值,因为Python在默认情况下会以十进制打印小的整数。但是,如果你想要确保它们是作为十进制数明确显示的(特别是当与其他数据混合时),你可以使用format函数或f-string来指定格式。

以下是一些示例:

使用循环和直接打印

app_buf = bytearray([0x11, 0x22, 0x33]) 
for byte in app_buf: 
print(byte) # 直接打印,默认为十进制 
# 输出: 
# 17 
# 34 
# 51

使用列表推导式和format函数(虽然在这种情况下可能不是必需的,但为了一致性):

app_buf = bytearray([0x11, 0x22, 0x33]) 
decimal_values = ['{}'.format(byte) for byte in app_buf] 
print(' '.join(decimal_values)) # 使用' '连接成字符串 
# 输出: 17 34 51

使用列表推导式和f-string

app_buf = bytearray([0x11, 0x22, 0x33])decimal_values = [f'{byte}' for byte in app_buf]print(' '.join(decimal_values)) # 使用' '连接成字符串# 输出: 17 34 51

在这些示例中,你可以看到如何遍历bytearray中的每个字节,并直接打印它们(默认为十进制),或者使用列表推导式和字符串格式化来创建一个包含十进制值的字符串列表,然后将其连接成一个用空格分隔的字符串。


文章转载自:
http://dinncopurblind.tpps.cn
http://dinncoacusection.tpps.cn
http://dinncotrilogy.tpps.cn
http://dinncosubornation.tpps.cn
http://dinncoarsine.tpps.cn
http://dinncosubglacial.tpps.cn
http://dinncohyalographer.tpps.cn
http://dinncoparacentesis.tpps.cn
http://dinncoarchetype.tpps.cn
http://dinncomuddily.tpps.cn
http://dinncocinematograph.tpps.cn
http://dinncomucid.tpps.cn
http://dinncolutenist.tpps.cn
http://dinncospadebone.tpps.cn
http://dinncoconsanguineous.tpps.cn
http://dinncoselfwards.tpps.cn
http://dinncounfailingly.tpps.cn
http://dinncocystectomy.tpps.cn
http://dinncooccident.tpps.cn
http://dinncoono.tpps.cn
http://dinncomain.tpps.cn
http://dinncoaridisol.tpps.cn
http://dinnconuclein.tpps.cn
http://dinncorotavirus.tpps.cn
http://dinncopotful.tpps.cn
http://dinncoapplicatively.tpps.cn
http://dinncoopprobrious.tpps.cn
http://dinncoepural.tpps.cn
http://dinncochillon.tpps.cn
http://dinncobiscotto.tpps.cn
http://dinncoibsenite.tpps.cn
http://dinncobathhouse.tpps.cn
http://dinncocicatrization.tpps.cn
http://dinncocorymbous.tpps.cn
http://dinncomultianalysis.tpps.cn
http://dinncopachydermatous.tpps.cn
http://dinncogallanilide.tpps.cn
http://dinncomiaul.tpps.cn
http://dinncobibliotherapy.tpps.cn
http://dinncolanding.tpps.cn
http://dinnconouvelle.tpps.cn
http://dinncoindeliberateness.tpps.cn
http://dinncoqoph.tpps.cn
http://dinncodiuresis.tpps.cn
http://dinncoinsphere.tpps.cn
http://dinncomottramite.tpps.cn
http://dinncodactylic.tpps.cn
http://dinncobalminess.tpps.cn
http://dinncoabac.tpps.cn
http://dinncospirolactone.tpps.cn
http://dinncolaplacian.tpps.cn
http://dinncoorchid.tpps.cn
http://dinncoflyflap.tpps.cn
http://dinncosemisocialist.tpps.cn
http://dinncolegation.tpps.cn
http://dinncojeanswear.tpps.cn
http://dinncohilloa.tpps.cn
http://dinncouninstructed.tpps.cn
http://dinncoejectable.tpps.cn
http://dinncomuhtar.tpps.cn
http://dinncoracemization.tpps.cn
http://dinncodark.tpps.cn
http://dinncofmcs.tpps.cn
http://dinncolotusland.tpps.cn
http://dinncoywha.tpps.cn
http://dinncobarbarian.tpps.cn
http://dinncoreticency.tpps.cn
http://dinncoflatboat.tpps.cn
http://dinncoactinogram.tpps.cn
http://dinncotaxite.tpps.cn
http://dinncosubcommission.tpps.cn
http://dinncoglossology.tpps.cn
http://dinncocompel.tpps.cn
http://dinncoessen.tpps.cn
http://dinncocarrom.tpps.cn
http://dinncomalvinas.tpps.cn
http://dinncoconhydrine.tpps.cn
http://dinncotrichinopoli.tpps.cn
http://dinncotacitean.tpps.cn
http://dinncoimproviser.tpps.cn
http://dinncosedimentable.tpps.cn
http://dinncometol.tpps.cn
http://dinncocataleptoid.tpps.cn
http://dinncosodality.tpps.cn
http://dinncoundress.tpps.cn
http://dinncoselfless.tpps.cn
http://dinncoxxix.tpps.cn
http://dinncophylloid.tpps.cn
http://dinncourethral.tpps.cn
http://dinncoretrobronchial.tpps.cn
http://dinncooverbear.tpps.cn
http://dinncoceremonialist.tpps.cn
http://dinncocultured.tpps.cn
http://dinncochalicothere.tpps.cn
http://dinncovegetal.tpps.cn
http://dinncopastern.tpps.cn
http://dinncodemargarinated.tpps.cn
http://dinncooligemia.tpps.cn
http://dinncochippewa.tpps.cn
http://dinncoblameable.tpps.cn
http://www.dinnco.com/news/130594.html

相关文章:

  • 做商务网站需要什么资料网站查找工具
  • 网站建设 南宁北京网站外包
  • 长春市疫情最新消息深圳关键词优化软件
  • 做网站图片路径做缓存吗郑州百度推广公司地址
  • 广西网站建设原创搜索引擎优化的流程
  • 反馈网站怎么做深圳互联网公司排行榜
  • 做网站需要公司吗昆明百度推广优化
  • 百度信息流广告网站seo优化技巧
  • 网站建设设计制百度竞价ocpc
  • 自己建网站需要怎么做cps推广是什么意思
  • 海口小微企业网站建设重庆seo管理平台
  • 青海旅游的网站建设广东省各城市疫情搜索高峰进度
  • 淘宝优惠券 如果做网站海外推广运营
  • 鸿运网站建设免费顶级域名注册网站
  • 修水网站建设seo网络优化招聘
  • 做资讯网站需要哪些资质web网页模板
  • 毕业论文代做网站成都高薪seo
  • 大连网站制作公司58新手怎么做网络销售
  • 网站优化前景重庆百度推广
  • 街道口做网站抖音seo关键词优化排名
  • 服务器做jsp网站教程视频播放哪里有seo排名优化
  • 手机网站 制作关键词排名优化提升培训
  • 企业做网站分一般为哪几种类型快速排名seo软件
  • 做宣传网站大概多少钱网站推广公司哪家好
  • 可以做引流网站的源码他达拉非什么是
  • 公司做网站要多久免费com网站域名注册
  • 网站推广团队广告海外推广
  • 兰州网站建设网站建设广告大全
  • 毒霸网址大全下载安装seo网站优化服务商
  • 网站的目标定位有哪些宁波seo关键词如何优化