Skip to main content
edit formatting & paraphrase
Source Link
blackraven
  • 5.7k
  • 7
  • 27
  • 51

append(object) - Updatesupdates the list by adding anthe object to the list.

x = [20]
# List passed to the append(object) method is treated as a single object.
x.append([21, 22, 23])
# Hence the resultant list length will be 2
print(x)
--> [20, [21, 22, 23]]

extend(list) - Essentially concatenates the two lists essentially.

x = [20]
# The parameter passed to extend(list) method is treated as a list.
# Eventually it is two lists being concatenated.
x.extend([21, 22, 23])
# Here the resultant list's length is 4
print(x)
--> [20, 21, 22, 23]

append(object) - Updates the list by adding an object to the list.

x = [20]
# List passed to the append(object) method is treated as a single object.
x.append([21, 22, 23])
# Hence the resultant list length will be 2
print(x)
--> [20, [21, 22, 23]]

extend(list) - Essentially concatenates two lists.

x = [20]
# The parameter passed to extend(list) method is treated as a list.
# Eventually it is two lists being concatenated.
x.extend([21, 22, 23])
# Here the resultant list's length is 4
print(x)
[20, 21, 22, 23]

append(object) updates the list by adding the object to the list.

x = [20]
# List passed to the append(object) method is treated as a single object.
x.append([21, 22, 23])
# Hence the resultant list length will be 2
print(x)
--> [20, [21, 22, 23]]

extend(list) concatenates the two lists essentially.

x = [20]
# The parameter passed to extend(list) method is treated as a list.
# Eventually it is two lists being concatenated.
x.extend([21, 22, 23])
# Here the resultant list's length is 4
print(x)
--> [20, 21, 22, 23]
Active reading. The examples now also works in Python 3 (tested on Python 3.6.3, Anaconda).
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

append(object)append(object) - Updates the list by adding an object to the list.

x = [20]
# listList passed to the append(object) method is treated as a single object.
x.append([21, 22, 23]) 
#hence# Hence the resultant list length will be 2
print (x )
--> [20, [21, 22, 23]]

extend(list)extend(list) - Essentially concatenates 2two lists.

x = [20]
#the# The parameter passed to extend(list) method is treated as a list.
#eventually# Eventually it is 2two list'slists being concatenated. 
x.extend([21, 22, 23])
#here# Here the resultant list's length is 4
print (x )
[20, 21, 22, 23]

append(object) - Updates the list by adding an object to the list.

x = [20]
# list passed to the append(object) method is treated as a single object.
x.append([21,22,23]) 
#hence the resultant list length will be 2
print x 
--> [20, [21,22,23]]

extend(list) - Essentially concatenates 2 lists.

x = [20]
#the parameter passed to extend(list) method is treated as a list.
#eventually it is 2 list's being concatenated. 
x.extend([21,22,23])
#here the resultant list's length is 4
print x 
[20,21,22,23]

append(object) - Updates the list by adding an object to the list.

x = [20]
# List passed to the append(object) method is treated as a single object.
x.append([21, 22, 23])
# Hence the resultant list length will be 2
print(x)
--> [20, [21, 22, 23]]

extend(list) - Essentially concatenates two lists.

x = [20]
# The parameter passed to extend(list) method is treated as a list.
# Eventually it is two lists being concatenated.
x.extend([21, 22, 23])
# Here the resultant list's length is 4
print(x)
[20, 21, 22, 23]
improved the answer with few examples.
Source Link
Chaitanya
  • 1.7k
  • 5
  • 21
  • 41

append(object) - Updates the list by adding an object to the list.

x = [20]
# list passed to the append(object) method is treated as a single object.
x.append([21,22,23]) 
#hence the resultant list length will be 2
print x 
--> [20, [21,22,23]]

extend(list) - Essentially concatenates 2 lists.

x = [20]
#the parameter passed to extend(list) method is treated as a list.
#eventually it is 2 list's being concatenated. 
x.extend([21,22,23])
#here the resultant list's length is 4
print x 
--> [20,21,22,23]

append(object) - Updates the list by adding an object to the list.

x = [20]
x.append([21,22,23])
print x 
--> [20, [21,22,23]]

extend(list) - Essentially concatenates 2 lists.

x = [20]
x.extend([21,22,23])
print x 
--> [20,21,22,23]

append(object) - Updates the list by adding an object to the list.

x = [20]
# list passed to the append(object) method is treated as a single object.
x.append([21,22,23]) 
#hence the resultant list length will be 2
print x 
--> [20, [21,22,23]]

extend(list) - Essentially concatenates 2 lists.

x = [20]
#the parameter passed to extend(list) method is treated as a list.
#eventually it is 2 list's being concatenated. 
x.extend([21,22,23])
#here the resultant list's length is 4
print x 
[20,21,22,23]
Source Link
Chaitanya
  • 1.7k
  • 5
  • 21
  • 41
Loading