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')
[解决办法]
这个当然是对的....
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楼说的是对的,你自己也可以试一下 呵呵~ 顶你一下
[解决办法]
正解啊