您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

python将字符串转换成数组的方法

2025/10/10 19:49:06发布20次查看
python将字符串转换成数组的方法。分享给大家供大家参考。具体实现方法如下:
#-----------------------------------------# name: string_to_array.py# author: kevin harris# last modified: 02/13/04# description: this python script demonstrates # how to modify a string by# converting it to an array#-----------------------------------------import arraystr = 'my name is kevin'print( 'str = ' + str )# we're not allowed to modify strings # so we'll need to convert it to a# character array instead...chararray = array.array( 'b', str )# assignmentchararray[11:16] = array.array( 'b', 'jason' )# replacementstr = chararray.tostring()# assignment back to the string objectprint( 'str = ' + str )input( '\n\npress enter to exit...' )
输出结果:
str = my name is kevinstr = my name is jason press enter to exit...
希望本文所述对大家的python程序设计有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product