Search
 
SCRIPT & CODE EXAMPLE
 

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')
Comment

PREVIOUS NEXT
Code Example
Python :: python merge two list 
Python :: heapsort python 
Python :: python length 
Python :: dict_keys to list 
Python :: remove all parentheses from string python 
Python :: merge dataframe using pandas 
Python :: create 2d array with rows and columns 
Python :: what is index in list in python 
Python :: NumPy flip Syntax 
Python :: python = align 
Python :: Python NumPy concatenate Function Example when axis equal to 1 
Python :: drop duplicates data frame pandas python 
Python :: how to invert a true false array in python 
Python :: with torch.no_grad() 
Python :: pandas grid subplots 
Python :: render to response django 
Python :: yahoo finance python documentation 
Python :: discard python 
Python :: how to add trailing zeros in python 
Python :: maximum count of replacements in python 
Python :: rename colonne pandas 
Python :: how to check if object is of file type in python3 
Python :: how to see truncated values in jupyter notebook 
Python :: add prefix to names in directory python 
Python :: fibonacci numbers in reverse order 
Python :: get admin url of instance django 
Python :: os.listdir specific extension 
Python :: how to get a list of files in a folder in python with pathlib 
Python :: Target Can Be Sum Of List Elements? 
Python :: pandas append new column 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =