首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python分割字符串,该怎么解决

2013-01-27 
Python分割字符串我写的python是要跟c#.net交互的,用的是IronPython例如有个字符串strExp a 1 and b

Python分割字符串
我写的python是要跟c#.net交互的,用的是IronPython

例如有个字符串strExp = "a = 1 and b = 2 and c = 3";
我想根据and 将字符串分割,放到数组中

在c#中可以通过 strExp.Split(new char[]{'a','n','d'});
我在py中这么写 strExp.Split(['a','n','d']); 通不过

请问在py中,如何根据and 分割strExp这个字符串?

[解决办法]
strExp.split('and')
[解决办法]

引用:
strExp.split('and')


这个当然是对的....
Python没有什么char,都是字符串


>>> strExp = "a = 1 and b = 2 and c = 3"
>>> strExp
'a = 1 and b = 2 and c = 3'
>>> strExp.split('and')
['a = 1 ', ' b = 2 ', ' c = 3']
>>> 

[解决办法]
3楼说的是对的,你自己也可以试一下 呵呵~ 顶你一下
[解决办法]
引用:
引用:

strExp.split('and')


这个当然是对的....
Python没有什么char,都是字符串


Python code

>>> strExp = "a = 1 and b = 2 and c = 3"
>>> strExp
'a = 1 and b = 2 and c = 3'
>>> strExp.split(……


正解啊

热点排行