Dictionary integer as key and function as value?

Viewed 7939

This is my code:

def test1():
  print("nr1")

def test2():
  print("nr2")

def test3():
  print("nr3")

def main():
  dictionary = { 1: test1(), 2: test2(), 3: test3() }
  dictionary[2]

if __name__ == "__main__":
  main()

This code returns:

nr1
nr2
nr3

What do I need to change in the code to get this:

nr2

I'm using Python 2.7.13.

3 Answers
Related