sum() method for list produces an error.
In the example for 6. For Loops - List , where data = [53,76,25,98,56,42,69,81] is used to demonstrate the sum() method, in my python console this produces an error. "TypeError: 'int' object is not callable"
I'm using python 3.8.8. Could this newer version of python be the reason? I know you are using Python 3.7 for the lecture.
Hey 이삭,
Thank you for your question!
Could you please provide the code you are using so that we can detect the problem?
Kind regards,
365 Hristina
I found the problem.
The issue was the data clearing in Spyder's Variable Explorer pane.
Do you know the difference between 'Refresh variables' button and 'Remove all variables' button?
Apparently only the 'Remove all variables' button seems to work. 'Refresh variables' button does not do anything.
Thanks.
Hey again,
Regarding the 'Refresh variables' button, here is an example that I took directly from the Spyder webpage. Consider the code below:
What it does is it starts from zero and ends at nine. For each number i
, we print i
and then assign a value of i*i
to the variable j
. Python then waits 10 seconds until it performs this operation on the next number. On the screenshot above, notice how the program is at i = 1
and j = 1
(in the console). However, I need to refresh my variable explorer in order to display the current values of the iterator i
and the variable j
while the program is running.
'Remove all variables', on the other hand, removes the variables from the memory of the computer. Consider for example the following piece of code which defines a variable x
. The variable is displayed in the variable explorer:
If I now execute a new code defining a variable y
, the old variable x
will still be stored in the memory of the computer:
This is where the button could come into play if you want to get rid of x
before executing the new code.
Hope this helps!
Kind regards,
Hristina