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.
python
add a comment |
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.
python
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
add a comment |
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.
python
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
python
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
add a comment |
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
add a comment |
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.
add a comment |
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered May 17 '15 at 11:14
Oka
10.9k42441
10.9k42441
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 11 at 10:38
Mark
1,33596
1,33596
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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