471,056 Members | 1,634 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,056 software developers and data experts.

what is wrong with my python code?

I got feed back saying" list object is not callable". But I can't figure out
what is wrong with my code.

A=[3,5,4,9,6,7]
l=len(A)-1

for i in range(l):
print A(i)
Feb 7 '07 #1
4 1285
"Dongsheng Ruan" <ru**@jcmills.comwrites:
for i in range(l):
print A(i)
Use square brackets, A[i].

Usually we'd write such a loop like this:

for x in A:
print x

Feb 7 '07 #2
On Wednesday 07 February 2007 12:43:34 Dongsheng Ruan wrote:
I got feed back saying" list object is not callable". But I can't figure
out what is wrong with my code.
for i in range(l):
print A(i)
You're calling A, when you want to access one of its elements: use the
straight brackets [

for i in range(l):
print A[i]
Feb 7 '07 #3
Dongsheng Ruan a écrit :
I got feed back saying" list object is not callable". But I can't figure out
what is wrong with my code.

A=[3,5,4,9,6,7]
l=len(A)-1

for i in range(l):
print A(i)
The error message is quite clear when you remember that () is the call
operator. For the subscribe operator, you want [].

And FWIW, Python for loops are smarter than that:
A = [3,5,4,9,6,7]
for i in A:
print i
Feb 7 '07 #4
On Feb 8, 4:43 am, "Dongsheng Ruan" <r...@jcmills.comwrote:
I got feed back saying" list object is not callable". But I can't figure out
what is wrong with my code.

A=[3,5,4,9,6,7]
l=len(A)-1

for i in range(l):
print A(i)
What the others said, *plus*:

(1) you are subtracting 1 off the length, so after the change from ()
to [], the last item would not be printed.

(2) have you considered working through a tutorial?

Cheers,
John
Feb 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
9 posts views Thread by Mike Henley | last post: by
7 posts views Thread by Michele Simionato | last post: by
92 posts views Thread by Reed L. O'Brien | last post: by
1 post views Thread by Leonard J. Reder | last post: by
137 posts views Thread by Philippe C. Martin | last post: by
5 posts views Thread by Nathan Pinno | last post: by
7 posts views Thread by kishkin | last post: by
34 posts views Thread by emrahayanoglu | last post: by
9 posts views Thread by Pyenos | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.