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 :: how to concatenate two lists in python 
Python :: import library to stop warnings in jupyter 
Python :: len python meaning 
Python :: python iterate over string 
Python :: matplotlib limit number of ticks 
Python :: Insert list element at specific index 
Python :: 2d array row and column index 
Python :: convert df.isnull().sum() to dataframe 
Python :: python sqlite select column name 
Python :: double a value in a list python 
Python :: how to tell python to go back to a previous line 
Python :: Python how to search in string 
Python :: Python program to print positive numbers in a list 
Python :: python new line 
Python :: text to image python 
Python :: how to get a row of a dataframe with subset columns in python 
Python :: python choose function 
Python :: python bin function without 0b 
Python :: Math Module log10() Function in python 
Python :: how to change the size of datapoint in plot python 
Python :: how to make code to do something for curtain number of seconds python 
Python :: login page in python flask with database 
Python :: import pycocotools._mask as _mask error Expected 80, got 88 
Python :: limpar idle python 
Python :: housie numbers using python 
Python :: list comprehensions in python 
Python :: request login python 
Python :: how to sort in python 
Python :: get path and name of file for open() 
Python :: godot get scenes from folder 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =