Skip to main content
Fixed Formatting.
Source Link
Prakhar Trivedi
  • 8.6k
  • 3
  • 30
  • 36

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly += for in place behavior, but with slight differences from append & extend. One of the biggest differences of += from append and extend is when it is used in function scopes, see this blog post:

https://www.toptal.com/python/top-10-mistakes-that-python-programmers-make?utm_medium=referral&utm_source=zeef.com&utm_campaign=ZEEFthis blog post.

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly += for in place behavior, but with slight differences from append & extend. One of the biggest differences of += from append and extend is when it is used in function scopes, see this blog post:

https://www.toptal.com/python/top-10-mistakes-that-python-programmers-make?utm_medium=referral&utm_source=zeef.com&utm_campaign=ZEEF

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly += for in place behavior, but with slight differences from append & extend. One of the biggest differences of += from append and extend is when it is used in function scopes, see this blog post.

added 261 characters in body
Source Link
den.run.ai
  • 6k
  • 18
  • 88
  • 146

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly += for in place behavior, but with slight differences from append & extend. One of the biggest differences of += from append and extend is when it is used in function scopes, see this blog post:

https://www.toptal.com/python/top-10-mistakes-that-python-programmers-make?utm_medium=referral&utm_source=zeef.com&utm_campaign=ZEEF

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly += for in place behavior, but with slight differences from append & extend.

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly += for in place behavior, but with slight differences from append & extend. One of the biggest differences of += from append and extend is when it is used in function scopes, see this blog post:

https://www.toptal.com/python/top-10-mistakes-that-python-programmers-make?utm_medium=referral&utm_source=zeef.com&utm_campaign=ZEEF

added 2 characters in body
Source Link
den.run.ai
  • 6k
  • 18
  • 88
  • 146

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly =++= for in place behavior, but with slight differences from append & extend.

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly =+ for in place behavior, but with slight differences from append & extend.

You can use "+" for returning extend, instead of extending in place.

l1=range(10) l1+[11] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11] l2=range(10,1,-1) l1+l2 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2] 

Similarly += for in place behavior, but with slight differences from append & extend.

added 68 characters in body; added 25 characters in body
Source Link
den.run.ai
  • 6k
  • 18
  • 88
  • 146
Loading
added 157 characters in body
Source Link
den.run.ai
  • 6k
  • 18
  • 88
  • 146
Loading
Copy edited.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
Source Link
den.run.ai
  • 6k
  • 18
  • 88
  • 146
Loading