Reputation: 7723
def extraction(content: str, channels: List[Color]=[Color.Red]):
pass
The second argument channels is a List of Color. However, what about if I also want to allow the possibility of channels being a str argument? In that case, it becomes:
def extraction(content: str, channels: str=None):
pass
Is it possible to combine the two definitions into one function definition?
Upvotes: 0
Views: 3661
Reputation: 63
To better implement this do the following:
from typing import Union
def extraction(content: str, channels: Union[str, List[Color]]) :
if type (channels) is str :
print ('channels is a string.')
if type (channels) is list :
print ('channels is a list.')
extraction ('testing', ['one, two three'])
Upvotes: 1
Reputation: 1500
def extraction(content: str, channels) :
if type (channels) is str :
print ('channels is a string.')
if type (channels) is list :
print ('channels is a list.')
extraction ('testing', ['one, two three'])
Upvotes: 2