Q. Given a list List1 = [1, 2, 3].


Run the following two statements for the list List1 and explain how these two statements are different:


List1 += 4 # statement

List1 += [4] # statement


Explanation


Answer =

Because in statement 1 there is addition of list and integer which is not possible. While in statement 2 there is addition of two lists which is possible.

1 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post