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,字符串,数组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python列表去重的二种方法
2022-06-02 05:21:41
Python 进程操作之进程间通过队列共享数据,队列Queue简单示例
2023-06-01 12:17:58
Django实现微信小程序的登录验证功能并维护登录态
2022-03-14 22:56:48
![](https://img.aspxhome.com/file/2023/6/76826_0s.png)
asp如何定义参数?
2010-05-16 15:20:00
web开发以HTML为中心
2008-02-13 08:14:00
![](https://img.aspxhome.com/file/UploadPic/20082/13/200821382345331s.png)
js用星投票的示例代码
2007-12-29 13:11:00
![](https://img.aspxhome.com/file/UploadPic/200712/29/20071229131618418s.gif)
段正淳的css笔记(7)-表单在各浏览器的表现统一
2008-01-14 02:47:00
IE及Opera浏览器兼容笔记
2008-08-21 17:53:00
用asp程序读取网站的alexa世界排名
2008-11-23 20:43:00
php生成4位数字验证码的实现代码
2023-11-20 15:00:12
Oracle性能究极优化 上第1/2页
2010-07-30 13:26:00
HTML5 WebSockets基础使用教程
2010-09-21 12:48:00
![](https://img.aspxhome.com/file/UploadPic/20109/21/01-97s.jpg)
asp是的日期转换为星座的函数
2011-02-26 11:11:00
SQLSERVER 本地查询更新操作远程数据库的代码
2023-07-23 21:58:55
python中Lambda表达式详解
2021-12-06 22:40:26
asp.net cookie清除的代码
2023-07-19 15:24:37
对python插入数据库和生成插入sql的示例讲解
2022-03-10 05:46:40
MySQL字段类型说明
2007-09-27 19:22:00
PHP缓存集成库phpFastCache用法
2023-11-14 02:35:19
python判断变量是否为int、字符串、列表、元组、字典的方法详解
2022-09-28 05:11:57