0

I read parts of the documentation and tried googling, but still feel pretty in the dark on basic syntax of how to use the data structures from the typing module.

from typing import List
A = List[int]

So once I've done the above, how do I even add new elements to A? I tried A += 5, A += [5], A.append(5), A.append([5])... I usually don't try to just haphazardly explore syntax, but I can't find much information online. Is there some syntax examples or tutorial page somewhere I'm missing?

Thanks.

user49404
  • 732
  • 6
  • 22
  • 1
    "how do I even add new elements to A" - you don't. You've made a type alias, not a list. Did you *want* a list? – user2357112 Dec 30 '20 at 17:20
  • 3
    `typing` doesn't provide *data structures*, it provides special-purpose objects that are supposed to serve as *type hints*. This is for people that are 1) reading the source code 2) third-party libraries, particularly for static analysis. – juanpa.arrivillaga Dec 30 '20 at 17:20
  • 2
    Some external related reading: [PEP 484 -- Type Hints](https://www.python.org/dev/peps/pep-0484/) and [typing — Support for type hints](https://docs.python.org/3/library/typing.html) – Tomerikoo Dec 30 '20 at 17:27

0 Answers0