Issue in Python lists

Question:

Here is my code:

list_b=[1,2,3,4,5,6,7,8,9,10]

print (list_b)
if(1 in list_b):
    t=list_b.append('hello')
    print(t)

else:
    t1=list_b.append(100)
    print(t1)

In the console it is showing me None. (Image)

Answers:

You haven’t stated the issue, but I’m assuming it’s this:

t=list_b.append('hello')

append() modifies the array, it doesn’t return a new array.

Answered By: Michael Bianconi

append() method does not return any value but updates existing list.
if you want to see the updated list, use print(list_b).
print(t) or print(t1) will return None as they don’t have any return values.

Answered By: A.N.Tanvir
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.