Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #以下代码段将展示如何编写一个不使用 if-else 条件的简单计算器。
- import operator
- action = {
- "+": operator.add,
- "-": operator.sub,
- "/": operator.truediv,
- "*": operator.mul,
- "**": pow
- }
- print(action[ - ](50, 25)) # 25
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement