Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python type annotations list of specific 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 :: why pytest return No ModuleError 
Python :: python check if string is url 
Python :: django jsonresponse 
Python :: python how to add columns to a pandas dataframe 
Python :: django model inheritance 
Python :: pandas difference between two dataframes 
Python :: insert into 2d array 
Python :: how to get last letter of string python 
Python :: to divide or not to divide codechef 
Python :: df set index 
Python :: python button tkinter change color 
Python :: create new columns pandas from another column 
Python :: values django 
Python :: python linux script 
Python :: python check characters in utf 8 
Python :: load specific columns dataframe 
Python :: zip lists 
Python :: tkinter canvas text 
Python :: python sort 2d list different sort order for different columns 
Python :: disable sns plot python 
Python :: python newline 
Python :: python append to dictionary 
Python :: tkinter set text 
Python :: python print exection type 
Python :: how to plot a single cluster 
Python :: remove df rows if two column values are not matching 
Python :: pd df replace 
Python :: email confirmation django 
Python :: django collectstatic with auto yes 
Python :: download google drive link collab 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =