Don’t use append but concatenation instead:
yourList = myList + [40]
This returns a new list; myList
will not be affected. If you need to have myList
affected as well either use .append()
anyway, then assign yourList
separately from (a copy of) myList
.
More Related Contents:
- What is the difference between Python’s list methods append and extend?
- Why does append() always return None in Python? [duplicate]
- Python append() vs. + operator on lists, why do these give different results?
- Why does foo.append(bar) affect all elements in a list of lists?
- What is the syntax to insert one list into another list in python?
- Appending item to lists within a list comprehension
- Appending a dictionary to a list in a loop
- How can I find same values in a list and group together a new list?
- Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?
- What’s the difference between plus and append in python for list manipulation? [duplicate]
- Python The appended element in the list changes as its original variable changes
- how to unpack a tuple in this form (‘abc’, [20, 20])? [closed]
- Pandas column of lists, create a row for each list element
- What is the difference between `sorted(list)` vs `list.sort()`?
- How can I get list of values from dict?
- Converting a string representation of a list into an actual list object [duplicate]
- Why does ‘.sort()’ cause the list to be ‘None’ in Python? [duplicate]
- Python’s insert returning None?
- why sum on lists is (sometimes) faster than itertools.chain?
- appending list but error ‘NoneType’ object has no attribute ‘append’ [duplicate]
- Get number of items from list (or other iterable) with certain condition
- How to remove square brackets from list in Python? [duplicate]
- accepting multiple user inputs separated by a space in python and append them to a list
- Unexpected list behavior in Python
- Why do these list operations (methods: clear / extend / reverse / append / sort / remove) return None, rather than the resulting list?
- Comprehension on a nested iterables?
- Slicing a list into n nearly-equal-length partitions [duplicate]
- Why do these list methods (append, sort, extend, remove, clear, reverse) return None rather than the resulting list?
- Sorting list according to corresponding values from a parallel list [duplicate]
- Does Python have an immutable list?