TypeError:’function’对象不可订阅 C Python
bank_holiday= [1,1,2,2] #gives the list of bank holidays in each month
def bank_holiday(month):
month -= 1#Takes away the numbers fro
|
我试图用这段代码解决一项任务: bank_holiday= [1,1,2,2] #gives the list of bank holidays in each month def bank_holiday(month): month -= 1#Takes away the numbers from the months,as months start at 1 (January) not at 0. There is no 0 month. print(bank_holiday[month]) bank_holiday(int(input("Which month would you like to check out: "))) 但是当我运行它时,我收到错误: TypeError: 'function' object is not subscriptable我不明白这是从哪里来的…… 解决方法 你有两个名为bank_holiday的对象 C 一个是列表,另一个是函数.消除两者的歧义.bank_holiday [month]引发错误,因为Python认为bank_holiday引用了函数(绑定到名称bank_holiday的最后一个对象),而您可能打算将其表示为列表. (编辑:东莞站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- python – Pandas列重新格式化
- python – 以任何方式使用时引发异常的对象
- 在Python的PIL中,如何更改图像的质量?
- 将电子表格的列存储在Python字典中
- python C 如何在PyCharm中找到所有未使用的类的方法?
- python – 如何使用输入函数和def函数?
- python – SqlAlchemy在保存之前将UTC DateTime转换为本地时
- python – pymongo:MongoClient或Connection
- 什么是好的编程问题,以在Python中运用“if … else”?
- python C 关于Pandas Dataframe的Kurtosis doent工作
- python – boto dynamodb2:我可以只使用范围键查
- 一个使用SimpleHTTPServer和SocketServer的简单的
- 在Python中更改循环内的循环变量
- python – 在数组末尾添加n个零
- python – Matplotlib显示多个图像与for循环
- python – 在Pandas DataFrame中分割列表
- python – 将numpy.array中的每个元素与numpy.ar
- Python:如何找到使用matplotlib绘制的图形的斜率
- python – 从Azure ML中的pyodbc连接到Azure SQL
- Python可以生成类似于bash的set -x的跟踪吗?
