【发布时间】:2014-10-06 14:58:37
【问题描述】:
当我尝试获取 lst1 (print(lst1)) 时遇到此代码问题,我收到此错误 NameError: name 'lst1' is not defined
我尝试了所有方法,但无法解决错误
# bkm( [500, 1024, 2000, 1100000] ) <- input
# ['0MB 0KB 500B', '0MB 1KB 0B', '0MB 1KB 976B', '1MB 50KB 224B'] <-this should be the output
def bkm(lst):
lst1=[]
for i in lst:
mb=i/1048576
i=i%1048576
kb=i/1024
b=i%1024
lst1=lst1+[str(mb)+'MB'+' '+str(kb)+'KB'+' '+str(b)+'B']
return lst1
bkm( [500, 1024, 2000, 1100000] )
print (lst1)
【问题讨论】:
-
您正试图访问函数外部的变量。