Reputation: 2324
Let say we have this simple arithmetic:
y = 1 + 1
Can I append the result of the arithmetic to a list directly like so:
num_list = []
l = num_list.append(y)
I have tried to print the list to see if the result has been appended to the list, but I noticed it gives me "None" as output. Any idea how to approach this?
Upvotes: 0
Views: 48
Reputation: 178
you should not print l
, you should print num_list
to see the appended list. Here is the sample test in python command line
>>> y = 1 + 1
>>> list1 = []
>>> list1.append(y)
>>> print list1
[2]
>>> print l
None
>>>
Upvotes: 2