博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python中列表元素和字符串之间的相互转化
阅读量:3510 次
发布时间:2019-05-20

本文共 525 字,大约阅读时间需要 1 分钟。

一、列表元素拼接成字符串

phone_num = ['123456','654321','147258']phone = ','.join(phone_num)print(phone)>>>123456,654321,147258phone = str(phone)print(phone)>>>'123456,654321,147258'phone_num = ['123456', '654321', '147258']phone = ''.join(phone_num)print(phone)>>>123456654321147258

二、字符串转化成列表元素

phone_num = '123456,654321,147258'phone = list(phone_num.split(','))print(phone)>>>['123456', '654321', '147258']

三、将一个连续的字符串数字分割开

phone_num = '123456654321147258'phone = ','.join(phone_num)print(phone)>>>1,2,3,4,5,6,6,5,4,3,2,1,1,4,7,2,5,8

转载地址:http://wfwqj.baihongyu.com/

你可能感兴趣的文章
vue router 报错: Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法
查看>>
vue跳转页面的两种方式
查看>>
存储器题目解析(持续更新中....)
查看>>
存储器知识要点
查看>>
Cache模拟器的实现
查看>>
实验2:MIPS指令系统和MIPS体系结构
查看>>
设计模式七大原则
查看>>
手写 | spring事务
查看>>
AndroidStudio Gradle手动下载
查看>>
SpringBoot入门(二)场景启动器
查看>>
SpringBoot入门--自动配置
查看>>
springboot读取配置文件 例:读取配置文件的优先顺序;在主配置文件中激活其他配置文件;加载非主配置文件
查看>>
自动配置原理
查看>>
TCP协议
查看>>
关于Linux系统使用遇到的问题-1:vi 打开只读(readonly)文件如何退出保存?
查看>>
redis 持久化详解,RDB和AOF是什么?他们优缺点是什么?运行流程是什么?
查看>>
spring注解版(一)
查看>>
SpringBoot中访问控制层(controller)得不到Json数据
查看>>
react项目报出警告Warning: Cannot update during an existing state transition (such as within `render`).
查看>>
BFC(Block Formatting Context)
查看>>