-1

I am trying to use a variable from a python list, but my code only returns the brackets of the list. Is there something I am doing wrong?

I have tried to remove the quotation marks, but that does not work either.

The list I want to retrieve values from:

date = [4, 1, 2000]

What I am doing:

print(date[0])

What it returns:

[

I was thinking that it does behave like this because maybe Python sees this as a string. However, while mapping and listing the list it still gives me the same error. Can somebody help me out?

Andras Deak
  • 27,857
  • 8
  • 66
  • 96
DeBruss
  • 9
  • 1
  • Possible duplicate of [Convert string representation of list to list](https://stackoverflow.com/questions/1894269/convert-string-representation-of-list-to-list) – pault Jun 15 '19 at 12:58

1 Answers1

3

If it is a list which I assume it is, it will work

date = [4, 1, 2000]
print(date[0])
#4

But if it is a string it won't work and show up what you saw

date = "[4, 1, 2000]"
print(date[0])

So check out the format of date

Devesh Kumar Singh
  • 19,316
  • 5
  • 17
  • 37