user3848207
user3848207

Reputation: 4927

Does this statement actually initialise the variable type in python?

I am using python 3.7. I have the following line for typing;

from typing import List
ConnectionOptions = List[str]

Does it actually initialise ConnectionOptions as a list of string or is it merely for typing purposes for static checking?

Reason I ask is usually typing statement uses : but this one doesn't.

Upvotes: 1

Views: 57

Answers (1)

user2357112
user2357112

Reputation: 281012

That doesn't create a list of strings. That creates a type alias - ConnectionOptions can now be used as an annotation meaning "list of strings".

If you want to create an empty list of strings, the way to do that is to use [], and then not put anything but strings in it.

Upvotes: 3

Related Questions