Python - TypeError: 'int' object is not callable

前端 未结 2 998
滥情空心
滥情空心 2021-01-20 16:11

(Using Python 2.7)

Hello,

I\'ve two version of a class PairOfDice.

1.) This one is not working and throws an error.

TypeErro

2条回答
  •  灰色年华
    2021-01-20 16:17

    In the first class total is a function as well as an attribute of the class. That is not okay :) Python thinks that the total you are referring to in the final line is the integer variable total and not the function.

    It is considered a good practice to name the function total as get_total instead

提交回复
热议问题