Py学习  »  Python

Python函数字典调用每个函数

Ken • 5 年前 • 1654 次点击  

这是我的密码:

class Calculator():
    def __init__(self):
        number = input()
        self.switch_case(number)

    def switch_case(self, number):
        switcher = {
            1: self.one(),
            2: self.two(),
        }

    def one(self):
        print("something")

    def two(self):
        print("something")

出于某种原因,即使我只输入值1作为输入,它也同时调用函数one()和two()。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56170
 
1654 次点击  
文章 [ 2 ]  |  最新文章 5 年前