假设我有一小段代码:
<?php
$tmp = str_split('hello world!',2);
// $tmp will now be: array('he','ll','o ','wo','rl','d!');
foreach($tmp AS &$a) {
// some processing
}
unset($tmp);
?>
Run Code Online (Sandbox Code Playgroud)
我怎么能在Python v2.7中做到这一点?
我以为这样做会:
the_string = 'hello world!'
tmp = the_string.split('',2)
for a in tmp:
# some processing
del tmp
Run Code Online (Sandbox Code Playgroud)
但它返回一个"空分隔符"错误.
有什么想法吗?