今天写几行代码解决工作问题,程序运行报报'builtin_function_or_method' object is not subscriptable 错误,
将代码简写如下
litterPigs = [] for boar in range(0,6): pig=[1,2,3,5 ] print(pig) try: litterPigs.append[pig] except BaseException as e: print(e)
运行结果为:
差了半天原因,最后发现是括号写错了,litterPigs.append[pig]中应该为litterPigs.append(pig)
改正后的代码和运行结果为
litterPigs = [] for boar in range(0,6): pig=[1,2,3,5 ] print(pig) try: litterPigs.append(pig) except BaseException as e: print(e) print("***********************************") print(litterPigs)标签:function,python,object,pig,builtin,print,litterPigs,method,append From: https://www.cnblogs.com/jilingxf/p/17146083.html