python将字符串转换成数组的方法
作者:重负在身 时间:2021-03-04 20:09:54
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 array
str = '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 )
# assignment
charArray[11:16] = array.array( 'B', 'Jason' )
# replacement
str = charArray.tostring()
# assignment back to the string object
print( 'str = ' + str )
input( '\n\nPress Enter to exit...' )
输出结果:
str = My name is Kevin
str = My name is Jason
Press Enter to exit...
希望本文所述对大家的python程序设计有所帮助。
标签:python,字符串,数组


猜你喜欢
Oracle merge合并更新函数实例详解
2023-07-23 02:45:02
ASP中Utf-8与Gb2312编码转换乱码问题的解决方法 页面编码声明
2012-11-30 20:45:55
Python面向对象程序设计之私有属性及私有方法示例
2023-11-21 06:29:04
Python+OpenCV图像处理——打印图片属性、设置存储路径、调用摄像头
2022-10-12 22:54:02
php计算函数执行时间的方法
2023-09-29 12:37:19
win7下 python3.6 安装opencv 和 opencv-contrib-python解决 cv2.xfeatures2d.SIFT_create() 的问题
2022-03-31 17:26:15
python将unicode和str互相转化的实现
2023-07-17 21:36:34
Python抓取今日头条街拍图片数据
2021-11-03 12:30:57

tensorflow之如何使用GPU而不是CPU问题
2023-07-06 13:05:48
ASP.NET MVC4入门教程(六):验证编辑方法和编辑视图
2024-05-13 09:15:36

opencv+python实现均值滤波
2023-10-21 15:00:58

js图片随机显示技巧
2007-08-19 20:20:00
使用ffmpeg 合并aac格式音频文件的方法
2023-05-25 02:44:56
从MySQL导大量数据的程序实现方法
2009-03-06 14:34:00
asp中用insert into语句向数据库插入记录(添加信息)的方法
2011-02-05 10:46:00
网页中的平衡、对比、连贯和留白
2008-11-24 12:11:00
你们要的Python绘画3D太阳系详细代码
2021-05-12 09:32:48

详解Python如何实现批量为PDF添加水印
2022-06-20 23:33:58

MySQL如何优雅的删除大表实例详解
2024-01-24 10:15:03
CentOS 6.5下安装Python 3.5.2(与Python2并存)
2021-06-24 04:33:54