|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def a(x):
list(x)
y = x.reverse
if y[0] != 5:
return sum(x)
else:
x.pop()
return sum(x)
运行结果是:
>>> a([1,2,3,4])
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
a([1,2,3,4])
File "F:/文件/研究生/Python/18.1.py", line 4, in a
if y[0] != 5:
TypeError: 'builtin_function_or_method' object is not subscriptable
求助
reverse 方法没有返回值,而且调用函数要加括号
- def a(x):
- x = list(x)
- y = x[:] # 拷贝列表
- y.reverse()
- if y[0] != 5:
- return sum(x)
- else:
- x.pop()
- return sum(x)
复制代码
|
|