我正在尝试运行此代码,我有一个列表列表.我需要添加到内部列表,但我得到错误
TypeError: 'list' object is not callable.
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这里我做错了什么.
def createlists():
global maxchar
global minchar
global worddict
global wordlists
for i in range(minchar, maxchar + 1):
wordlists.insert(i, list())
#add data to list now
for words in worddict.keys():
print words
print wordlists(len(words)) # <--- Error here.
(wordlists(len(words))).append(words) # <-- Error here too
print "adding word " + words + " at " + str(wordlists(len(words)))
print wordlists(5)
Run Code Online (Sandbox Code Playgroud) 我试图用这段代码解决一项任务:
bank_holiday= [1, 0, 1, 1, 2, 0, 0, 1, 0, 0, 0, 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: ")))
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我收到错误:
TypeError: 'function' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)
我不明白这是从哪里来的......
我是一名刚开始学习 Python(第 3 版)的非程序员,并且对我的代码中何时需要方括号与圆括号有点困惑。
是否有一般的经验法则?
假设你写bytes(10),根据我的理解,这将创建一个 10 个字节的字节数组;但是,如果您改为写入bytes([10]),则会得到二进制值 10。
方括号对数字的数据类型有什么影响?作为操作员,我找不到有关它们的任何信息。