fork download
  1. def checkArg(arg: str| list[str]) -> str:
  2. match arg:
  3. case str():
  4. return 'str'
  5. case [*items] if all(isinstance(item, str) for item in items):
  6. return 'list(str)'
  7. case _:
  8. return "unmatched"
  9.  
  10. def test(arg: str|list[str]):
  11. print(f'{arg=!r}: {checkArg(arg)}')
  12.  
  13. test(0)
  14. test('This should match')
  15. test(['This','should','match'])
  16. test(['This','should',0,'not','match'])
Success #stdin #stdout 0.1s 14116KB
stdin
Standard input is empty
stdout
arg=0: unmatched
arg='This should match': str
arg=['This', 'should', 'match']: list(str)
arg=['This', 'should', 0, 'not', 'match']: unmatched