2010-04-23 88 views

回答

12

你可能会输错连字符和下划线,尝试

a_front = len(a)/2 + len(a) % 2 
+2

是啊,这工作。找出 - 是负运算符 – mzee 2010-04-23 10:09:12

1

这是更Python这样:

a = "foo bar baz" 
front = a[:len(a)/2]    # integer division with truncating 
front = a[:int(round(len(a)/2.0))] # float division with rounding