1

I came across the code below,

period=volume[((volume['Id']==report.at[report.index[report_id],'id']) & \
                                       (volume['Time']>=start_time) & \
                                      (volume['Time']<=test_time))]

I read a post on operator & but what does it mean by &\ and what is this snippet of code doing?

nilsinelabore
  • 4,143
  • 17
  • 65
  • 122
  • 1
    It means the author doesn't know that inside parentheses, you don't need ``\`` to tell Python the logical line isn't finished but continues on the next physical line. – Kelly Bundy Feb 12 '20 at 03:09
  • 2
    The backslash at the end of a line escapes the linebreak and effectively means: continue in the next line. In the given case it is not even necessary since there are brackets open. – Klaus D. Feb 12 '20 at 03:11
  • 1
    `&\ ` are two characters that just happened to be together. `&` is the bitwise _and_ operator.`\ ` is a line continuation character. – DYZ Feb 12 '20 at 03:12
  • 1
    https://docs.python.org/3/reference/lexical_analysis.html#explicit-line-joining – Kelly Bundy Feb 12 '20 at 03:14

1 Answers1

0

The backslash doesn't create another operator with the &, it is just used to allow one long statement to continue onto the next line for readability. So the code is equivalent to

period=volume[((volume['Id']==report.at[report.index[report_id],'id']) & (volume['Time']>=start_time) & (volume['Time']<=test_time))]
jbinvnt
  • 498
  • 2
  • 7
  • 16