Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python type hint list of possible values

# use typing.Literal - mode expects either 'a' or 'b'
from typing import Literal

def func(mode: Literal['a', 'b'] = 'a'):
    if mode not in ['a', 'b']:
        raise AttributeError('Not OK')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #type #hint #list #values
ADD COMMENT
Topic
Name
2+4 =