Why does b+=(4,) work and b = b + (4,) doesn't work when b is a list?What exactly does += do in python?Is the behaviour of Python's list += iterable documented anywhere?Why can't I add a tuple to a list with the '+' operator in Python?Understanding Python's builtins operator overloading behaviorHow do I check if a list is empty?Finding the index of an item given a list containing it in PythonWhat does the “yield” keyword do?What is the difference between Python's list methods append and extend?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?How to make a flat list out of list of listsHow to clone or copy a list?Why not inherit from List<T>?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?

SSD or HDD for server

'provocative' vs 'sexy'

How is Smough's name pronounced?

'Pound' meaning in this context

How to respond to "Why didn't you do a postdoc after your PhD?"

Does a reincarnated Draconic Bloodline Sorcerer save his class abilities?

How can a company compel a W2 employee to sign a non-compete agreement?

Is fascism intrinsically violent?

I'm trying to graph a rational function

Proofreading a novel: is it okay to use a question mark with an exclamation mark - "?!"

I got this nail stuck in my tire, should I plug or replace?

Can I get bubble tea at Taiyuan airport?

How to get the SMILES of all compounds on PubChem?

d-Menthol vs dl-menthol: Does an enantiomer and its racemic mixture have different melting points?

Can you take an Immortal Phoenix out of the game?

Rule of thumb: how far before changing my chain to prevent cassette wear

Is the Thief Rogue's Thief's Reflexes feature optional?

Did smallpox emerge in 1580?

Is it plausible that an interrupted Windows update can cause the motherboard to fail?

A fast aquatic predator with multiple eyes and pupils. Would these eyes be possible?

Is it reasonable to ask candidates to create a profile on Google Scholar?

Do you say "good game" after a game in which your opponent played poorly?

How can a "proper" function have a vertical slope?

Is the value of a probability density function for a given input a point, a range, or both?



Why does b+=(4,) work and b = b + (4,) doesn't work when b is a list?


What exactly does += do in python?Is the behaviour of Python's list += iterable documented anywhere?Why can't I add a tuple to a list with the '+' operator in Python?Understanding Python's builtins operator overloading behaviorHow do I check if a list is empty?Finding the index of an item given a list containing it in PythonWhat does the “yield” keyword do?What is the difference between Python's list methods append and extend?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?How to make a flat list out of list of listsHow to clone or copy a list?Why not inherit from List<T>?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









9

















If we take b = [1,2,3] and if we try doing b+=(4,) it returns b = [1,2,3,4], but if we try doing b = b + (4,) it doesn't work.



b = [1,2,3]
b+=(4,) # Prints out b = [1,2,3,4]
b = b + (4,) # Gives an error saying you can't add tuples and lists


I expected b+=(4,) to fail as you can't add a list and a tuple, but it worked. So I tried b = b + (4,) expecting to get the same result, but it didn't work.










share|improve this question









New contributor



Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • 2





    I believe an answer can be found here.

    – jochen
    10 hours ago











  • or stackoverflow.com/questions/9897070/…

    – splash58
    10 hours ago











  • At first I misread this and tried to close it as too broad, then retracted it. Then I thought it had to be a duplicate, but not only could I not re-cast a vote, I pulled my hair out trying to find other answers like those. :/

    – Karl Knechtel
    9 hours ago











  • Very similar question: stackoverflow.com/questions/58048664/…

    – sanyash
    9 hours ago

















9

















If we take b = [1,2,3] and if we try doing b+=(4,) it returns b = [1,2,3,4], but if we try doing b = b + (4,) it doesn't work.



b = [1,2,3]
b+=(4,) # Prints out b = [1,2,3,4]
b = b + (4,) # Gives an error saying you can't add tuples and lists


I expected b+=(4,) to fail as you can't add a list and a tuple, but it worked. So I tried b = b + (4,) expecting to get the same result, but it didn't work.










share|improve this question









New contributor



Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • 2





    I believe an answer can be found here.

    – jochen
    10 hours ago











  • or stackoverflow.com/questions/9897070/…

    – splash58
    10 hours ago











  • At first I misread this and tried to close it as too broad, then retracted it. Then I thought it had to be a duplicate, but not only could I not re-cast a vote, I pulled my hair out trying to find other answers like those. :/

    – Karl Knechtel
    9 hours ago











  • Very similar question: stackoverflow.com/questions/58048664/…

    – sanyash
    9 hours ago













9












9








9


1






If we take b = [1,2,3] and if we try doing b+=(4,) it returns b = [1,2,3,4], but if we try doing b = b + (4,) it doesn't work.



b = [1,2,3]
b+=(4,) # Prints out b = [1,2,3,4]
b = b + (4,) # Gives an error saying you can't add tuples and lists


I expected b+=(4,) to fail as you can't add a list and a tuple, but it worked. So I tried b = b + (4,) expecting to get the same result, but it didn't work.










share|improve this question









New contributor



Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











If we take b = [1,2,3] and if we try doing b+=(4,) it returns b = [1,2,3,4], but if we try doing b = b + (4,) it doesn't work.



b = [1,2,3]
b+=(4,) # Prints out b = [1,2,3,4]
b = b + (4,) # Gives an error saying you can't add tuples and lists


I expected b+=(4,) to fail as you can't add a list and a tuple, but it worked. So I tried b = b + (4,) expecting to get the same result, but it didn't work.







python python-3.x list tuples






share|improve this question









New contributor



Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question



share|improve this question








edited 54 mins ago









Peter Mortensen

14.5k19 gold badges89 silver badges118 bronze badges




14.5k19 gold badges89 silver badges118 bronze badges






New contributor



Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 10 hours ago









Supun Dasantha KuruppuSupun Dasantha Kuruppu

461 bronze badge




461 bronze badge




New contributor



Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Supun Dasantha Kuruppu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 2





    I believe an answer can be found here.

    – jochen
    10 hours ago











  • or stackoverflow.com/questions/9897070/…

    – splash58
    10 hours ago











  • At first I misread this and tried to close it as too broad, then retracted it. Then I thought it had to be a duplicate, but not only could I not re-cast a vote, I pulled my hair out trying to find other answers like those. :/

    – Karl Knechtel
    9 hours ago











  • Very similar question: stackoverflow.com/questions/58048664/…

    – sanyash
    9 hours ago












  • 2





    I believe an answer can be found here.

    – jochen
    10 hours ago











  • or stackoverflow.com/questions/9897070/…

    – splash58
    10 hours ago











  • At first I misread this and tried to close it as too broad, then retracted it. Then I thought it had to be a duplicate, but not only could I not re-cast a vote, I pulled my hair out trying to find other answers like those. :/

    – Karl Knechtel
    9 hours ago











  • Very similar question: stackoverflow.com/questions/58048664/…

    – sanyash
    9 hours ago







2




2





I believe an answer can be found here.

– jochen
10 hours ago





I believe an answer can be found here.

– jochen
10 hours ago













or stackoverflow.com/questions/9897070/…

– splash58
10 hours ago





or stackoverflow.com/questions/9897070/…

– splash58
10 hours ago













At first I misread this and tried to close it as too broad, then retracted it. Then I thought it had to be a duplicate, but not only could I not re-cast a vote, I pulled my hair out trying to find other answers like those. :/

– Karl Knechtel
9 hours ago





At first I misread this and tried to close it as too broad, then retracted it. Then I thought it had to be a duplicate, but not only could I not re-cast a vote, I pulled my hair out trying to find other answers like those. :/

– Karl Knechtel
9 hours ago













Very similar question: stackoverflow.com/questions/58048664/…

– sanyash
9 hours ago





Very similar question: stackoverflow.com/questions/58048664/…

– sanyash
9 hours ago












3 Answers
3






active

oldest

votes


















7


















The problem with "why" questions is that usually they can mean multiple different things. I will try to answer each one I think you might have in mind.



"Why is it possible for it to work differently?" which is answered by e.g. this. Basically, += tries to use different methods of the object: __iadd__ (which is only checked on the left-hand side), vs __add__ and __radd__ ("reverse add", checked on the right-hand side if the left-hand side doesn't have __add__) for +.



"What exactly does each version do?" In short, the list.__iadd__ method does the same thing as list.extend (but because of the language design, there is still an assignment back).



This also means for example that



>>> a = [1,2,3]
>>> b = a
>>> a += [4] # uses the .extend logic, so it is still the same object
>>> b # therefore a and b are still the same list, and b has the `4` added
[1, 2, 3, 4]
>>> b = b + [5] # makes a new list and assigns back to b
>>> a # so now a is a separate list and does not have the `5`
[1, 2, 3, 4]


+, of course, creates a new object, but explicitly requires another list instead of trying to pull elements out of a different sequence.



"Why is it useful for += to do this? It's more efficient; the extend method doesn't have to create a new object. Of course, this has some surprising effects sometimes (like above), and generally Python is not really about efficiency, but these decisions were made a long time ago.



"What is the reason not to allow adding lists and tuples with +?" See here (thanks, @splash58); one idea is that (tuple + list) should produce the same type as (list + tuple), and it's not clear which type the result should be. += doesn't have this problem, because a += b obviously should not change the type of a.



You can see similar reasoning elsewhere, e.g.



>>> 1,2,3.union([4,5])
1, 2, 3, 4, 5
>>> 1,2,3 + [4,5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'set' and 'list'


The named method of set is allowed to take multiple new elements from a list; the operator version is not - because maybe the result should be a list instead? It's ambiguous, so Python refuses to guess.






share|improve this answer


























  • The union operator for sets is | not +.

    – a_guest
    7 hours ago


















3


















They are not equivalent:



b += (4,)


is shorthand for:



b.extend((4,))


while + concatenates lists, so by:



b = b + (4,)


you're trying to concatenate a tuple to a list






share|improve this answer

































    0


















    From the official docs, for mutable sequence types both:



    s += t
    s.extend(t)


    are defined as:




    extends s with the contents of t




    Which is different than being defined as:



    s = s + t # not equivalent in Python!


    This also means any sequence type will work for t, including a tuple like in your example.



    But it also works for ranges and generators! For instance, you can also do:



    s += range(3)





    share|improve this answer



























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );







      Supun Dasantha Kuruppu is a new contributor. Be nice, and check out our Code of Conduct.









      draft saved

      draft discarded
















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58259682%2fwhy-does-b-4-work-and-b-b-4-doesnt-work-when-b-is-a-list%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown


























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7


















      The problem with "why" questions is that usually they can mean multiple different things. I will try to answer each one I think you might have in mind.



      "Why is it possible for it to work differently?" which is answered by e.g. this. Basically, += tries to use different methods of the object: __iadd__ (which is only checked on the left-hand side), vs __add__ and __radd__ ("reverse add", checked on the right-hand side if the left-hand side doesn't have __add__) for +.



      "What exactly does each version do?" In short, the list.__iadd__ method does the same thing as list.extend (but because of the language design, there is still an assignment back).



      This also means for example that



      >>> a = [1,2,3]
      >>> b = a
      >>> a += [4] # uses the .extend logic, so it is still the same object
      >>> b # therefore a and b are still the same list, and b has the `4` added
      [1, 2, 3, 4]
      >>> b = b + [5] # makes a new list and assigns back to b
      >>> a # so now a is a separate list and does not have the `5`
      [1, 2, 3, 4]


      +, of course, creates a new object, but explicitly requires another list instead of trying to pull elements out of a different sequence.



      "Why is it useful for += to do this? It's more efficient; the extend method doesn't have to create a new object. Of course, this has some surprising effects sometimes (like above), and generally Python is not really about efficiency, but these decisions were made a long time ago.



      "What is the reason not to allow adding lists and tuples with +?" See here (thanks, @splash58); one idea is that (tuple + list) should produce the same type as (list + tuple), and it's not clear which type the result should be. += doesn't have this problem, because a += b obviously should not change the type of a.



      You can see similar reasoning elsewhere, e.g.



      >>> 1,2,3.union([4,5])
      1, 2, 3, 4, 5
      >>> 1,2,3 + [4,5]
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      TypeError: unsupported operand type(s) for +: 'set' and 'list'


      The named method of set is allowed to take multiple new elements from a list; the operator version is not - because maybe the result should be a list instead? It's ambiguous, so Python refuses to guess.






      share|improve this answer


























      • The union operator for sets is | not +.

        – a_guest
        7 hours ago















      7


















      The problem with "why" questions is that usually they can mean multiple different things. I will try to answer each one I think you might have in mind.



      "Why is it possible for it to work differently?" which is answered by e.g. this. Basically, += tries to use different methods of the object: __iadd__ (which is only checked on the left-hand side), vs __add__ and __radd__ ("reverse add", checked on the right-hand side if the left-hand side doesn't have __add__) for +.



      "What exactly does each version do?" In short, the list.__iadd__ method does the same thing as list.extend (but because of the language design, there is still an assignment back).



      This also means for example that



      >>> a = [1,2,3]
      >>> b = a
      >>> a += [4] # uses the .extend logic, so it is still the same object
      >>> b # therefore a and b are still the same list, and b has the `4` added
      [1, 2, 3, 4]
      >>> b = b + [5] # makes a new list and assigns back to b
      >>> a # so now a is a separate list and does not have the `5`
      [1, 2, 3, 4]


      +, of course, creates a new object, but explicitly requires another list instead of trying to pull elements out of a different sequence.



      "Why is it useful for += to do this? It's more efficient; the extend method doesn't have to create a new object. Of course, this has some surprising effects sometimes (like above), and generally Python is not really about efficiency, but these decisions were made a long time ago.



      "What is the reason not to allow adding lists and tuples with +?" See here (thanks, @splash58); one idea is that (tuple + list) should produce the same type as (list + tuple), and it's not clear which type the result should be. += doesn't have this problem, because a += b obviously should not change the type of a.



      You can see similar reasoning elsewhere, e.g.



      >>> 1,2,3.union([4,5])
      1, 2, 3, 4, 5
      >>> 1,2,3 + [4,5]
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      TypeError: unsupported operand type(s) for +: 'set' and 'list'


      The named method of set is allowed to take multiple new elements from a list; the operator version is not - because maybe the result should be a list instead? It's ambiguous, so Python refuses to guess.






      share|improve this answer


























      • The union operator for sets is | not +.

        – a_guest
        7 hours ago













      7














      7










      7









      The problem with "why" questions is that usually they can mean multiple different things. I will try to answer each one I think you might have in mind.



      "Why is it possible for it to work differently?" which is answered by e.g. this. Basically, += tries to use different methods of the object: __iadd__ (which is only checked on the left-hand side), vs __add__ and __radd__ ("reverse add", checked on the right-hand side if the left-hand side doesn't have __add__) for +.



      "What exactly does each version do?" In short, the list.__iadd__ method does the same thing as list.extend (but because of the language design, there is still an assignment back).



      This also means for example that



      >>> a = [1,2,3]
      >>> b = a
      >>> a += [4] # uses the .extend logic, so it is still the same object
      >>> b # therefore a and b are still the same list, and b has the `4` added
      [1, 2, 3, 4]
      >>> b = b + [5] # makes a new list and assigns back to b
      >>> a # so now a is a separate list and does not have the `5`
      [1, 2, 3, 4]


      +, of course, creates a new object, but explicitly requires another list instead of trying to pull elements out of a different sequence.



      "Why is it useful for += to do this? It's more efficient; the extend method doesn't have to create a new object. Of course, this has some surprising effects sometimes (like above), and generally Python is not really about efficiency, but these decisions were made a long time ago.



      "What is the reason not to allow adding lists and tuples with +?" See here (thanks, @splash58); one idea is that (tuple + list) should produce the same type as (list + tuple), and it's not clear which type the result should be. += doesn't have this problem, because a += b obviously should not change the type of a.



      You can see similar reasoning elsewhere, e.g.



      >>> 1,2,3.union([4,5])
      1, 2, 3, 4, 5
      >>> 1,2,3 + [4,5]
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      TypeError: unsupported operand type(s) for +: 'set' and 'list'


      The named method of set is allowed to take multiple new elements from a list; the operator version is not - because maybe the result should be a list instead? It's ambiguous, so Python refuses to guess.






      share|improve this answer














      The problem with "why" questions is that usually they can mean multiple different things. I will try to answer each one I think you might have in mind.



      "Why is it possible for it to work differently?" which is answered by e.g. this. Basically, += tries to use different methods of the object: __iadd__ (which is only checked on the left-hand side), vs __add__ and __radd__ ("reverse add", checked on the right-hand side if the left-hand side doesn't have __add__) for +.



      "What exactly does each version do?" In short, the list.__iadd__ method does the same thing as list.extend (but because of the language design, there is still an assignment back).



      This also means for example that



      >>> a = [1,2,3]
      >>> b = a
      >>> a += [4] # uses the .extend logic, so it is still the same object
      >>> b # therefore a and b are still the same list, and b has the `4` added
      [1, 2, 3, 4]
      >>> b = b + [5] # makes a new list and assigns back to b
      >>> a # so now a is a separate list and does not have the `5`
      [1, 2, 3, 4]


      +, of course, creates a new object, but explicitly requires another list instead of trying to pull elements out of a different sequence.



      "Why is it useful for += to do this? It's more efficient; the extend method doesn't have to create a new object. Of course, this has some surprising effects sometimes (like above), and generally Python is not really about efficiency, but these decisions were made a long time ago.



      "What is the reason not to allow adding lists and tuples with +?" See here (thanks, @splash58); one idea is that (tuple + list) should produce the same type as (list + tuple), and it's not clear which type the result should be. += doesn't have this problem, because a += b obviously should not change the type of a.



      You can see similar reasoning elsewhere, e.g.



      >>> 1,2,3.union([4,5])
      1, 2, 3, 4, 5
      >>> 1,2,3 + [4,5]
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      TypeError: unsupported operand type(s) for +: 'set' and 'list'


      The named method of set is allowed to take multiple new elements from a list; the operator version is not - because maybe the result should be a list instead? It's ambiguous, so Python refuses to guess.







      share|improve this answer













      share|improve this answer




      share|improve this answer



      share|improve this answer










      answered 9 hours ago









      Karl KnechtelKarl Knechtel

      39.7k5 gold badges64 silver badges96 bronze badges




      39.7k5 gold badges64 silver badges96 bronze badges















      • The union operator for sets is | not +.

        – a_guest
        7 hours ago

















      • The union operator for sets is | not +.

        – a_guest
        7 hours ago
















      The union operator for sets is | not +.

      – a_guest
      7 hours ago





      The union operator for sets is | not +.

      – a_guest
      7 hours ago













      3


















      They are not equivalent:



      b += (4,)


      is shorthand for:



      b.extend((4,))


      while + concatenates lists, so by:



      b = b + (4,)


      you're trying to concatenate a tuple to a list






      share|improve this answer






























        3


















        They are not equivalent:



        b += (4,)


        is shorthand for:



        b.extend((4,))


        while + concatenates lists, so by:



        b = b + (4,)


        you're trying to concatenate a tuple to a list






        share|improve this answer




























          3














          3










          3









          They are not equivalent:



          b += (4,)


          is shorthand for:



          b.extend((4,))


          while + concatenates lists, so by:



          b = b + (4,)


          you're trying to concatenate a tuple to a list






          share|improve this answer














          They are not equivalent:



          b += (4,)


          is shorthand for:



          b.extend((4,))


          while + concatenates lists, so by:



          b = b + (4,)


          you're trying to concatenate a tuple to a list







          share|improve this answer













          share|improve this answer




          share|improve this answer



          share|improve this answer










          answered 10 hours ago









          alfasinalfasin

          45.3k10 gold badges58 silver badges100 bronze badges




          45.3k10 gold badges58 silver badges100 bronze badges
























              0


















              From the official docs, for mutable sequence types both:



              s += t
              s.extend(t)


              are defined as:




              extends s with the contents of t




              Which is different than being defined as:



              s = s + t # not equivalent in Python!


              This also means any sequence type will work for t, including a tuple like in your example.



              But it also works for ranges and generators! For instance, you can also do:



              s += range(3)





              share|improve this answer






























                0


















                From the official docs, for mutable sequence types both:



                s += t
                s.extend(t)


                are defined as:




                extends s with the contents of t




                Which is different than being defined as:



                s = s + t # not equivalent in Python!


                This also means any sequence type will work for t, including a tuple like in your example.



                But it also works for ranges and generators! For instance, you can also do:



                s += range(3)





                share|improve this answer




























                  0














                  0










                  0









                  From the official docs, for mutable sequence types both:



                  s += t
                  s.extend(t)


                  are defined as:




                  extends s with the contents of t




                  Which is different than being defined as:



                  s = s + t # not equivalent in Python!


                  This also means any sequence type will work for t, including a tuple like in your example.



                  But it also works for ranges and generators! For instance, you can also do:



                  s += range(3)





                  share|improve this answer














                  From the official docs, for mutable sequence types both:



                  s += t
                  s.extend(t)


                  are defined as:




                  extends s with the contents of t




                  Which is different than being defined as:



                  s = s + t # not equivalent in Python!


                  This also means any sequence type will work for t, including a tuple like in your example.



                  But it also works for ranges and generators! For instance, you can also do:



                  s += range(3)






                  share|improve this answer













                  share|improve this answer




                  share|improve this answer



                  share|improve this answer










                  answered 7 hours ago









                  AcornAcorn

                  11.3k2 gold badges19 silver badges50 bronze badges




                  11.3k2 gold badges19 silver badges50 bronze badges
























                      Supun Dasantha Kuruppu is a new contributor. Be nice, and check out our Code of Conduct.









                      draft saved

                      draft discarded

















                      Supun Dasantha Kuruppu is a new contributor. Be nice, and check out our Code of Conduct.












                      Supun Dasantha Kuruppu is a new contributor. Be nice, and check out our Code of Conduct.











                      Supun Dasantha Kuruppu is a new contributor. Be nice, and check out our Code of Conduct.














                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58259682%2fwhy-does-b-4-work-and-b-b-4-doesnt-work-when-b-is-a-list%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown









                      Popular posts from this blog

                      Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                      Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                      199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單