BODMAS - python











up vote
0
down vote

favorite












I thought I understood BODMAS (BIDMAS in the UK). I'm unsure why the following expression evaluates in a different order:



a = 8*4//3


I expected 'division' to take place first, giving a = 8*1 - instead 'multiplication' occurs first, giving a = 32//3 = 10



b = 9//3*7


Example b evaluates to 21, as per BIDMAS rule.



It seems that python executes an expression from left to right and treats 'division' and 'multiplication' as equivalent. What's happening? Thanks in advance, Faz.










share|improve this question




















  • 1




    no, * and / have the same priority. So, the symbol appears first would be evaluated first.
    – Avinash Raj
    May 17 '15 at 11:01










  • Operations of equal rank are evaluated from left to right by the "BODMAS" rule...
    – Tim Pietzcker
    May 17 '15 at 11:01






  • 1




    Division and multiplication have the same precedence, with the leftmost operator winning the tie. It is the same for addition and subtraction. Even in BODMAS, multiplication/division are associative, it's just that when you write the acronym, one has to come before the other. The choice is arbitrary.
    – Asad Saeeduddin
    May 17 '15 at 11:02






  • 1




    Python Docs | Operator precedence
    – Lukas Graf
    May 17 '15 at 11:03












  • It's BIMDAS in the south east of UK by the way, so that does make sense to me
    – Clive
    May 17 '15 at 11:04















up vote
0
down vote

favorite












I thought I understood BODMAS (BIDMAS in the UK). I'm unsure why the following expression evaluates in a different order:



a = 8*4//3


I expected 'division' to take place first, giving a = 8*1 - instead 'multiplication' occurs first, giving a = 32//3 = 10



b = 9//3*7


Example b evaluates to 21, as per BIDMAS rule.



It seems that python executes an expression from left to right and treats 'division' and 'multiplication' as equivalent. What's happening? Thanks in advance, Faz.










share|improve this question




















  • 1




    no, * and / have the same priority. So, the symbol appears first would be evaluated first.
    – Avinash Raj
    May 17 '15 at 11:01










  • Operations of equal rank are evaluated from left to right by the "BODMAS" rule...
    – Tim Pietzcker
    May 17 '15 at 11:01






  • 1




    Division and multiplication have the same precedence, with the leftmost operator winning the tie. It is the same for addition and subtraction. Even in BODMAS, multiplication/division are associative, it's just that when you write the acronym, one has to come before the other. The choice is arbitrary.
    – Asad Saeeduddin
    May 17 '15 at 11:02






  • 1




    Python Docs | Operator precedence
    – Lukas Graf
    May 17 '15 at 11:03












  • It's BIMDAS in the south east of UK by the way, so that does make sense to me
    – Clive
    May 17 '15 at 11:04













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I thought I understood BODMAS (BIDMAS in the UK). I'm unsure why the following expression evaluates in a different order:



a = 8*4//3


I expected 'division' to take place first, giving a = 8*1 - instead 'multiplication' occurs first, giving a = 32//3 = 10



b = 9//3*7


Example b evaluates to 21, as per BIDMAS rule.



It seems that python executes an expression from left to right and treats 'division' and 'multiplication' as equivalent. What's happening? Thanks in advance, Faz.










share|improve this question















I thought I understood BODMAS (BIDMAS in the UK). I'm unsure why the following expression evaluates in a different order:



a = 8*4//3


I expected 'division' to take place first, giving a = 8*1 - instead 'multiplication' occurs first, giving a = 32//3 = 10



b = 9//3*7


Example b evaluates to 21, as per BIDMAS rule.



It seems that python executes an expression from left to right and treats 'division' and 'multiplication' as equivalent. What's happening? Thanks in advance, Faz.







python






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 17 '15 at 11:08









Darek Kay

9,09244350




9,09244350










asked May 17 '15 at 10:58









Mr malik

612




612








  • 1




    no, * and / have the same priority. So, the symbol appears first would be evaluated first.
    – Avinash Raj
    May 17 '15 at 11:01










  • Operations of equal rank are evaluated from left to right by the "BODMAS" rule...
    – Tim Pietzcker
    May 17 '15 at 11:01






  • 1




    Division and multiplication have the same precedence, with the leftmost operator winning the tie. It is the same for addition and subtraction. Even in BODMAS, multiplication/division are associative, it's just that when you write the acronym, one has to come before the other. The choice is arbitrary.
    – Asad Saeeduddin
    May 17 '15 at 11:02






  • 1




    Python Docs | Operator precedence
    – Lukas Graf
    May 17 '15 at 11:03












  • It's BIMDAS in the south east of UK by the way, so that does make sense to me
    – Clive
    May 17 '15 at 11:04














  • 1




    no, * and / have the same priority. So, the symbol appears first would be evaluated first.
    – Avinash Raj
    May 17 '15 at 11:01










  • Operations of equal rank are evaluated from left to right by the "BODMAS" rule...
    – Tim Pietzcker
    May 17 '15 at 11:01






  • 1




    Division and multiplication have the same precedence, with the leftmost operator winning the tie. It is the same for addition and subtraction. Even in BODMAS, multiplication/division are associative, it's just that when you write the acronym, one has to come before the other. The choice is arbitrary.
    – Asad Saeeduddin
    May 17 '15 at 11:02






  • 1




    Python Docs | Operator precedence
    – Lukas Graf
    May 17 '15 at 11:03












  • It's BIMDAS in the south east of UK by the way, so that does make sense to me
    – Clive
    May 17 '15 at 11:04








1




1




no, * and / have the same priority. So, the symbol appears first would be evaluated first.
– Avinash Raj
May 17 '15 at 11:01




no, * and / have the same priority. So, the symbol appears first would be evaluated first.
– Avinash Raj
May 17 '15 at 11:01












Operations of equal rank are evaluated from left to right by the "BODMAS" rule...
– Tim Pietzcker
May 17 '15 at 11:01




Operations of equal rank are evaluated from left to right by the "BODMAS" rule...
– Tim Pietzcker
May 17 '15 at 11:01




1




1




Division and multiplication have the same precedence, with the leftmost operator winning the tie. It is the same for addition and subtraction. Even in BODMAS, multiplication/division are associative, it's just that when you write the acronym, one has to come before the other. The choice is arbitrary.
– Asad Saeeduddin
May 17 '15 at 11:02




Division and multiplication have the same precedence, with the leftmost operator winning the tie. It is the same for addition and subtraction. Even in BODMAS, multiplication/division are associative, it's just that when you write the acronym, one has to come before the other. The choice is arbitrary.
– Asad Saeeduddin
May 17 '15 at 11:02




1




1




Python Docs | Operator precedence
– Lukas Graf
May 17 '15 at 11:03






Python Docs | Operator precedence
– Lukas Graf
May 17 '15 at 11:03














It's BIMDAS in the south east of UK by the way, so that does make sense to me
– Clive
May 17 '15 at 11:04




It's BIMDAS in the south east of UK by the way, so that does make sense to me
– Clive
May 17 '15 at 11:04












3 Answers
3






active

oldest

votes

















up vote
2
down vote













In BEDMAS, BIDMAS, BOMDAS, BODMAS, PEDMAS, and other order of operations acronyms, division and multiplication carry the same weight and are calculated from left to right within their current block.



Read this section for clarification.






share|improve this answer




























    up vote
    0
    down vote













    If you do a multiplication and a division it doesn't matter which order you do it in for example 6*5/3 = 10 the same as 6/3*5 = 10. The difference comes with addition where 6+3*5 = 21 but (6+3)*5 = 45.






    share|improve this answer





















    • Not entirely; try changing the 3 to 4, in Python2 you get 6 * 5 / 4 = 7, 6 / 4 * 5 = 5; Python3 6 * 5 // 4 = 7, 6 // 4 * 5 = 5.
      – Mark
      Nov 11 at 10:28


















    up vote
    0
    down vote













    Turning the comments on the OP into an independent answer, as this post shows up at the top of search results:



    Multiplication & Division have equal precedence in Python, as well as according to the BODMAS/BEDMAS/BIDMAS/BIMDAS/BOMDAS/PEDMAS rule, so the evaluation then proceeds from Left to Right Python2 docs






    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',
      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/3.0/"u003ecc by-sa 3.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
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30286140%2fbodmas-python%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








      up vote
      2
      down vote













      In BEDMAS, BIDMAS, BOMDAS, BODMAS, PEDMAS, and other order of operations acronyms, division and multiplication carry the same weight and are calculated from left to right within their current block.



      Read this section for clarification.






      share|improve this answer

























        up vote
        2
        down vote













        In BEDMAS, BIDMAS, BOMDAS, BODMAS, PEDMAS, and other order of operations acronyms, division and multiplication carry the same weight and are calculated from left to right within their current block.



        Read this section for clarification.






        share|improve this answer























          up vote
          2
          down vote










          up vote
          2
          down vote









          In BEDMAS, BIDMAS, BOMDAS, BODMAS, PEDMAS, and other order of operations acronyms, division and multiplication carry the same weight and are calculated from left to right within their current block.



          Read this section for clarification.






          share|improve this answer












          In BEDMAS, BIDMAS, BOMDAS, BODMAS, PEDMAS, and other order of operations acronyms, division and multiplication carry the same weight and are calculated from left to right within their current block.



          Read this section for clarification.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 17 '15 at 11:14









          Oka

          10.9k42441




          10.9k42441
























              up vote
              0
              down vote













              If you do a multiplication and a division it doesn't matter which order you do it in for example 6*5/3 = 10 the same as 6/3*5 = 10. The difference comes with addition where 6+3*5 = 21 but (6+3)*5 = 45.






              share|improve this answer





















              • Not entirely; try changing the 3 to 4, in Python2 you get 6 * 5 / 4 = 7, 6 / 4 * 5 = 5; Python3 6 * 5 // 4 = 7, 6 // 4 * 5 = 5.
                – Mark
                Nov 11 at 10:28















              up vote
              0
              down vote













              If you do a multiplication and a division it doesn't matter which order you do it in for example 6*5/3 = 10 the same as 6/3*5 = 10. The difference comes with addition where 6+3*5 = 21 but (6+3)*5 = 45.






              share|improve this answer





















              • Not entirely; try changing the 3 to 4, in Python2 you get 6 * 5 / 4 = 7, 6 / 4 * 5 = 5; Python3 6 * 5 // 4 = 7, 6 // 4 * 5 = 5.
                – Mark
                Nov 11 at 10:28













              up vote
              0
              down vote










              up vote
              0
              down vote









              If you do a multiplication and a division it doesn't matter which order you do it in for example 6*5/3 = 10 the same as 6/3*5 = 10. The difference comes with addition where 6+3*5 = 21 but (6+3)*5 = 45.






              share|improve this answer












              If you do a multiplication and a division it doesn't matter which order you do it in for example 6*5/3 = 10 the same as 6/3*5 = 10. The difference comes with addition where 6+3*5 = 21 but (6+3)*5 = 45.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jul 7 '16 at 8:59









              Drew

              1




              1












              • Not entirely; try changing the 3 to 4, in Python2 you get 6 * 5 / 4 = 7, 6 / 4 * 5 = 5; Python3 6 * 5 // 4 = 7, 6 // 4 * 5 = 5.
                – Mark
                Nov 11 at 10:28


















              • Not entirely; try changing the 3 to 4, in Python2 you get 6 * 5 / 4 = 7, 6 / 4 * 5 = 5; Python3 6 * 5 // 4 = 7, 6 // 4 * 5 = 5.
                – Mark
                Nov 11 at 10:28
















              Not entirely; try changing the 3 to 4, in Python2 you get 6 * 5 / 4 = 7, 6 / 4 * 5 = 5; Python3 6 * 5 // 4 = 7, 6 // 4 * 5 = 5.
              – Mark
              Nov 11 at 10:28




              Not entirely; try changing the 3 to 4, in Python2 you get 6 * 5 / 4 = 7, 6 / 4 * 5 = 5; Python3 6 * 5 // 4 = 7, 6 // 4 * 5 = 5.
              – Mark
              Nov 11 at 10:28










              up vote
              0
              down vote













              Turning the comments on the OP into an independent answer, as this post shows up at the top of search results:



              Multiplication & Division have equal precedence in Python, as well as according to the BODMAS/BEDMAS/BIDMAS/BIMDAS/BOMDAS/PEDMAS rule, so the evaluation then proceeds from Left to Right Python2 docs






              share|improve this answer

























                up vote
                0
                down vote













                Turning the comments on the OP into an independent answer, as this post shows up at the top of search results:



                Multiplication & Division have equal precedence in Python, as well as according to the BODMAS/BEDMAS/BIDMAS/BIMDAS/BOMDAS/PEDMAS rule, so the evaluation then proceeds from Left to Right Python2 docs






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Turning the comments on the OP into an independent answer, as this post shows up at the top of search results:



                  Multiplication & Division have equal precedence in Python, as well as according to the BODMAS/BEDMAS/BIDMAS/BIMDAS/BOMDAS/PEDMAS rule, so the evaluation then proceeds from Left to Right Python2 docs






                  share|improve this answer












                  Turning the comments on the OP into an independent answer, as this post shows up at the top of search results:



                  Multiplication & Division have equal precedence in Python, as well as according to the BODMAS/BEDMAS/BIDMAS/BIMDAS/BOMDAS/PEDMAS rule, so the evaluation then proceeds from Left to Right Python2 docs







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 at 10:38









                  Mark

                  1,33596




                  1,33596






























                      draft saved

                      draft discarded




















































                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f30286140%2fbodmas-python%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

                      Bressuire

                      Vorschmack

                      Quarantine