0

I try to run the code:

for c in range(10, 21):
    print(c)
    print([c[1]])

And I get the error: TypeError: 'int' object is not callable Why? How can I pick a specific element from an integer?

Loocid
  • 5,639
  • 1
  • 19
  • 39

2 Answers2

0
result = [i for i in range(10,21)]
for c in result:
    print(c)
    print(result[1])

#what you are trying is illegal in python. Int 'int' object is not subscribable. #Only lists or tuples, set, string... are subscriptable.

krishna
  • 1
  • 3
-2

you are iterating in an iterable, you need to declare before the list to access to the element something like this:

a = range(10,21)
for i in a:
    print(i)
    print(a[1])

In your code every iteration the value of c are: 10 11 12 13 ... This is the reason of you error