Python append function inserts letters into List

   2562   1   0
User Avatar
Member
2041 posts
Joined: Sept. 2015
Offline
Hello,

I'm not very experienced with coding in Python and have come across something that seems peculiar.

The following function is what I have in the Python Source Editor.

When I run the function in the Python Shell, it is showing the letter L is added to two numbers.

I inserted a print command just before they are inserted in the list to use as a check of the values before appending.

So it appears these Letters are getting inserted during the append operation.

I can only guess I am not using the append function properly?

def Create_Sequence():
Sequence = []
Previous = 0
Current = 1
for Count in range(100):
Next = Current
Current = Previous + Current
Previous = Next
Result = Current % 40
Contains = 0
for Count2 in range(len(Sequence)):
if(Sequence[Count2] == Result):
Contains = 1
if( Contains == 0 ):
print Result
Sequence.append(Result)

return Sequence
User Avatar
Member
2041 posts
Joined: Sept. 2015
Offline
Did another search and found the second time round that it was mentioned the L stands for long.

So I tried to ‘caste’ all my appends with int and it works

Sequence.append(int(Result))
Edited by BabaJ - April 21, 2017 09:01:39
  • Quick Links