Skip to main content

An English dictionary definedefines the words append and extend as:

append: add (something) to the end of a written document.
extend: make larger. Enlarge or expand


With that knowledge, now let's understand

  1. The difference between append and extend

append:

  • Appends any Python object as-is to the end of the list (i.e. as a lastthe last element in the list).
  • The resulting list may be nested and contain heterogeneous elements (i.e. list, string, tuple, dictionary, set, etc.)

extend:

  • Accepts any iterable as its argument and makes the list larger.
  • The resulting list is always one dimensional-dimensional list (i.e. no nesting) and it may contain heterogeneous elements in it (e.g. characters, integers, float) as a result of applying list(iterable).
  1. Similarity between append and extend
  • Both takestake exactly one argument.
  • Both modify the list in-place.
  • As a result, both returns None.

Example

lis = [1, 2, 3]

# 'extend' is equivalent to this
lis = lis + list(iterable)

# 'append' simply appends its argument as the last element to the list
# as long as the argument is a valid Python object
lislist.append(object)

An English dictionary define the words append and extend as:

append: add (something) to the end of a written document.
extend: make larger. Enlarge or expand


With that knowledge, now let's understand

  1. The difference between append and extend

append:

  • Appends any Python object as-is to the end of the list (i.e. as a last element in the list).
  • The resulting list may be nested and contain heterogeneous elements (i.e. list, string, tuple, dictionary, set, etc.)

extend:

  • Accepts any iterable as its argument and makes the list larger.
  • The resulting list is always one dimensional list (i.e. no nesting) and it may contain heterogeneous elements in it (e.g. characters, integers, float) as a result of applying list(iterable).
  1. Similarity between append and extend
  • Both takes exactly one argument.
  • Both modify the list in-place.
  • As a result, both returns None.

Example

lis = [1, 2, 3]

# 'extend' is equivalent to this
lis = lis + list(iterable)

# 'append' simply appends its argument as the last element to the list
# as long as the argument is a valid Python object
lis.append(object)

An English dictionary defines the words append and extend as:

append: add (something) to the end of a written document.
extend: make larger. Enlarge or expand


With that knowledge, now let's understand

  1. The difference between append and extend

append:

  • Appends any Python object as-is to the end of the list (i.e. as a the last element in the list).
  • The resulting list may be nested and contain heterogeneous elements (i.e. list, string, tuple, dictionary, set, etc.)

extend:

  • Accepts any iterable as its argument and makes the list larger.
  • The resulting list is always one-dimensional list (i.e. no nesting) and it may contain heterogeneous elements in it (e.g. characters, integers, float) as a result of applying list(iterable).
  1. Similarity between append and extend
  • Both take exactly one argument.
  • Both modify the list in-place.
  • As a result, both returns None.

Example

lis = [1, 2, 3]

# 'extend' is equivalent to this
lis = lis + list(iterable)

# 'append' simply appends its argument as the last element to the list
# as long as the argument is a valid Python object
list.append(object)
Active reading.
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

An English dictionary define the words append and extend as:

append: add (something) to the end of a written document.
  
extend: make larger. enlargeEnlarge or expand


With that knowledge, now let's understand

  1. differenceThe difference between append and extend

append:

  • appendsAppends any Python object as-is to the end of the list (i.e. as a last element in the list).
  • The resulting list may be nested and contain heterogeneous elements (i.e. list, string, tuple, dictionary, set, etc.)

extend:

  • acceptsAccepts any iterable as its argument and makes the list larger.
  • The resulting list is always one dimensional list (i.e. no nesting) and it may contain heterogeneous elements in it (e.g. characters, integers, float) as a result of applying list(iterable).
  1. similaritySimilarity between append and extend
  • Both takes exactly one argument.
  • Both modify the list in-place.
  • As a result, both returns None.

Example

lis = [1, 2, 3]

# extend'extend' is equivalent to this
lis = lis + list(iterable)

# append'append' simply appends its argument as the last element to the list
# as long as the argument is a valid Python object
lis.append(object)

English dictionary define the words append and extend as:

append: add (something) to the end of a written document.
  extend: make larger. enlarge or expand


With that knowledge, now let's understand

  1. difference between append and extend

append:

  • appends any Python object as-is to the end of the list (i.e. as a last element in the list).
  • resulting list may be nested and contain heterogeneous elements (i.e. list, string, tuple, dictionary, set etc.)

extend:

  • accepts any iterable as its argument and makes the list larger
  • resulting list is always one dimensional list (i.e. no nesting) and it may contain heterogeneous elements in it (e.g. characters, integers, float) as a result of applying list(iterable)
  1. similarity between append and extend
  • Both takes exactly one argument
  • Both modify the list in-place
  • As a result, both returns None

Example

lis = [1, 2, 3]

# extend is equivalent to this
lis = lis + list(iterable)

# append simply appends its argument as the last element to the list
# as long as the argument is a valid Python object
lis.append(object)

An English dictionary define the words append and extend as:

append: add (something) to the end of a written document.  
extend: make larger. Enlarge or expand


With that knowledge, now let's understand

  1. The difference between append and extend

append:

  • Appends any Python object as-is to the end of the list (i.e. as a last element in the list).
  • The resulting list may be nested and contain heterogeneous elements (i.e. list, string, tuple, dictionary, set, etc.)

extend:

  • Accepts any iterable as its argument and makes the list larger.
  • The resulting list is always one dimensional list (i.e. no nesting) and it may contain heterogeneous elements in it (e.g. characters, integers, float) as a result of applying list(iterable).
  1. Similarity between append and extend
  • Both takes exactly one argument.
  • Both modify the list in-place.
  • As a result, both returns None.

Example

lis = [1, 2, 3]

# 'extend' is equivalent to this
lis = lis + list(iterable)

# 'append' simply appends its argument as the last element to the list
# as long as the argument is a valid Python object
lis.append(object)
Source Link
kmario23
  • 62.3k
  • 17
  • 175
  • 160

English dictionary define the words append and extend as:

append: add (something) to the end of a written document.
extend: make larger. enlarge or expand


With that knowledge, now let's understand

  1. difference between append and extend

append:

  • appends any Python object as-is to the end of the list (i.e. as a last element in the list).
  • resulting list may be nested and contain heterogeneous elements (i.e. list, string, tuple, dictionary, set etc.)

extend:

  • accepts any iterable as its argument and makes the list larger
  • resulting list is always one dimensional list (i.e. no nesting) and it may contain heterogeneous elements in it (e.g. characters, integers, float) as a result of applying list(iterable)
  1. similarity between append and extend
  • Both takes exactly one argument
  • Both modify the list in-place
  • As a result, both returns None

Example

lis = [1, 2, 3]

# extend is equivalent to this
lis = lis + list(iterable)

# append simply appends its argument as the last element to the list
# as long as the argument is a valid Python object
lis.append(object)