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 :: python type hint list of specific values 
Python :: python merge two array into one 
Python :: jsonresponse django 
Python :: python added dictionary together 
Python :: counter library python 
Python :: how to round to the nearest tenth in python 
Python :: 2d array row and column 
Python :: how to submit two forms in django 
Python :: To Divide or Not To Divide 
Python :: replace in lists py 
Python :: tkinter python button 
Python :: #find the difference in days between two dates. 
Python :: proper pagination django template 
Python :: long in python 
Python :: python while loop guessing game 
Python :: how to find missing item in a list 
Python :: python warnings as error 
Python :: tkinter add text to canvas 
Python :: check if digit or alphabet 
Python :: CVE-2018-10933 
Python :: python is scripting language or programming language 
Python :: python remove item from a list 
Python :: Delete cell in jupiter notebook 
Python :: where to put capybara default wait time 
Python :: Mac: Access your iCloud Documents folder with Jupyter Notebook or JupyterLab 
Python :: django add to cart 
Python :: 1 12 123 python 
Python :: Code Example of Hashmap in Python 
Python :: shibang for python file in linux 
Python :: Python update to beginning of dictionary 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =