Append function

Append function
0.0 0

#1

Hi can anyone help me?

I was trying to append a number into the list on jupyter notebook but it didn’t work and I’m stuck. (I did restart the jupyter note book but it dorps the same error.)

So my code was:

a = {44, 9, -10}

print(a)
{9, 44, -10}

a.append(1)
AttributeError Traceback (most recent call last)
in ()
----> 1 a.append(1)

AttributeError: ‘set’ object has no attribute ‘append’


#2

because the brackets arent square.
change the bracket to square bracket and it will work, correct me if im wrong


#3

Hi There, thank you for helping me out.

Here are the results:
a.append[1]

AttributeError Traceback (most recent call last)
in ()
----> 1 a.append[1]

AttributeError: ‘set’ object has no attribute ‘append’

or:

a.append{1}
File “”, line 1
a.append{1}
^
SyntaxError: invalid syntax

The weird thing is that my this code (a.append(1)) is exactly the same to a person’s but it just wouldn’t work on my jupyter notebook even I restarted it again and again.

I downloaded this person’s code and run it on my jupyter notebook and it’s working.


#4

your code needs to look like this:

<p> 
 a = [44, 9,-10]
print(a)

a.append(1)
print(a)

#5

I just found out the rel problem is from the first code:

I wrote a = {44, 9, -10}, but it should be a = [44, 9, -10].

Thank you anyway!


#6

Yes I also just found out. Thank you very much!