Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialpawkan kenluecha
26,303 PointsIs it still valid to use "range()" ?
Hello.
I tried to use this code in console and I got this error.
our_list = list(range(10))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'range' object is not callable
What is the meaning of this ? Is this still possible to use ?
2 Answers
jacinator
11,936 PointsThe only thing that I can see is that you are redefining range somewhere before that in your code. When I redefined range, then I got the same error as you, but without redefining it, list(range(10))
should work fine.
Alex Donald
Courses Plus Student 13,129 PointsI had this issue because I had previously used "list" as a variable. Therefore Python was trying to pass the range to my list. Perhaps I should be more inventive with variable names!
pawkan kenluecha
26,303 Pointspawkan kenluecha
26,303 PointsSo, Is that some kinds of a bug in the console ? I've seen the same thing in the instruction video. Sometimes when he tried to use some function, it's error. And after he re-typed it again,he could execute properly.
jacinator
11,936 Pointsjacinator
11,936 PointsNot a bug, really. It's an exception (or an error). Python throws you an exception when it can't perform what you've asked it to do. For some reason it's giving you a TypeError exception regarding range; which means that range isn't set up the way that it should normally be. The only solution to that which I can see is that you are overwriting range.
I'm assuming that you've assigned range to a variable since it's telling you that it's not callable. Variables aren't callable, and since functions and objects are, I don't see another way that this could be happening.
pawkan kenluecha
26,303 Pointspawkan kenluecha
26,303 PointsThe problem is I am very certain that I wouldn't have defined it as a variable. Keyword "range" isn't suitable to declare at that exercise. Because most of that lesson was taking about "list". I think I should drop this topic out, whether it's a bug or not I can execute it by now when I reopen the new windows. Thanks for the answers though.