Append method not working

The following pages offer essential information about this forum, including how to format Python code for proper display:

Based on information from the first of those two links, we can format your code for display using backticks by doing this:

```
List = [1,2,3,4]
Newlist = List.append(7)
print(Newlist)
```

When formatted with the above technique, your code would appear as follows in the post:

List = [1,2,3,4]
Newlist = List.append(7)
print(Newlist)

Note that the formatted code is easier to read than the unformatted code that you originally posted. In formatted code, important details, such as any indentation that it might contain, would also be visible.

Let’s consider in detail what your code appears to be intended to do. Please let us know if anything about the following is mistaken.

It seems that you are attempting to create two lists, with the second one being a copy of the first, but with 7 appended to it. So, after we create the first list, we need to copy it to create the second one. There are several techniques available for copying a list, and we will use one of them. After we have a copy of the first list, we can modify it without altering the contents of the first list.

Note that it is conventional among Python programmers to begin the names of variables with lowercase letters.

Below is a revision of your code. Please feel free to ask us any questions that you may have about it.

numbers_a = [1,2,3,4]
numbers_b = numbers_a.copy()
numbers_b.append(7)
print(numbers_a)
print(numbers_b)

Output:

[1, 2, 3, 4]
[1, 2, 3, 4, 7]