我想在Python中编写一个函数,它根据输入索引的值返回不同的固定值.
在其他语言中,我会使用switch或case声明,但Python似乎没有switch声明.在这种情况下,推荐的Python解决方案是什么?
似乎应该有一个比以下更简单的方法:
import string
s = "string. With. Punctuation?" # Sample string
out = s.translate(string.maketrans("",""), string.punctuation)
Run Code Online (Sandbox Code Playgroud)
在那儿?