我正在尝试在类似于下面所示的函数中使用多个案例,以便我能够使用 python 3.10 中的匹配案例来执行多个案例
def sayHi(name):
match name:
case ['Egide', 'Eric']:
return f"Hi Mr {name}"
case 'Egidia':
return f"Hi Ms {name}"
print(sayHi('Egide'))
这只是回归None
而不是消息,即使我删除了方括号。
根据Python 3.10 的新增功能 https://docs.python.org/3/whatsnew/3.10.html#pep-634-structural-pattern-matching,
PEP 636 https://peps.python.org/pep-0636/#or-patterns, and
the docs https://docs.python.org/3/reference/compound_stmts.html#or-patterns,
你用一个|
模式之间:
case 'Egide' | 'Eric':
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)