0
I would like to understand why t2 is null after assignment of t1+append.
t1=[1,2]
t2=t1.append(3)
print(t2)
0
I would like to understand why t2 is null after assignment of t1+append.
t1=[1,2]
t2=t1.append(3)
print(t2)
2
The append() method has no return, it simply does the action of adding a new item to the list. Therefore, when you try to "printar" a return of append, it returns None.
You can do it like this to work:
t1=[1,2]
t2=t1
t2.append(3)
print(t2)
1
Hi, append is sticking a new element (can be a new list) to a current list. To add 3 at the end of the list the command is:
t1=[1,2]
t1.append(3)
print(t1)
Now if you want to append one list to the other first you need to declare the other, then it would be
t1=[1,2]
t2=[3,4]
t1.append(t2)
print(t1)
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
.append age in the list, and retorn None, the correct ai, would be just, t1.append(3); print(t1)
– Elton Nunes