0

I'm stumped on a line of code in Python that I'm supposed to translate. Most websites don't have a clearer example of my situation now.

output_qr_dim, and i are just integers

output_r[output_qr_dim * i:output_qr_dim * i + output_qr_dim, output_qr_dim * j:output_qr_dim * j + output_qr_dim] = ra

At first I thought it means you just complete the operations on either sides of the :, then only perform the slicing. But according to this website, http://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html, the slicing takes precedence over the other operations, so I'm rather confused at the moment.

Any help would be appreciated

MigfibOri
  • 73
  • 7
  • 1
    That table is rather confusing; use the [Python reference documentation](https://docs.python.org/3/reference/expressions.html#operator-precedence) instead. – Martijn Pieters Apr 13 '18 at 07:52
  • 1
    And precedence is about binding order. It means the `output_r[...]` part is executed first before other expressions *around* it, it doesn't mean that component expressions that make up the slice are somehow calculated afterwards. – Martijn Pieters Apr 13 '18 at 07:53
  • 1
    the precedence table you linked says that *slicing* itself has a high precedence than other operatrions, not that the `:` has a higher precedence than the other operations *within* the slicing. All calculations inside the `[]` will be finished, *then* the results will be used for slicing. If there are other operations on the same line as the slice (but outside of the brackets), then the entire slicing operation (including the calculations inside the brackets) will complete before the outside calculations. – Zinki Apr 13 '18 at 08:02
  • 1
    @Zinki: in the end the user should just focus on translating the slice to the other language; they got themselves all confused over precedence while all they need is to understand slicing. Precedence is a red herring here. – Martijn Pieters Apr 13 '18 at 08:08

0 Answers0