-1

I'm a beginner both with python and openpyxl so please bear with me.

I'm learning excel manipulation using excel to automate some tasks at work and I encountered this line from the openpyxl tutorial

for row in range(10, 20):
    for col in range(27, 54):
        _ = ws3.cell(column=col, row=row, value="{0}".format(get_column_letter(col)))

what does the 3rd line do? what does the underscore on the left mean?

this is from https://openpyxl.readthedocs.io/en/default/usage.html

chip
  • 3,039
  • 5
  • 35
  • 59
  • 2
    I don't know openpyxl, but the underscore generally signifies a "throwaway" variable, meaning that the function has a side-effect and also returns something, but you don't care about that something (only about the side effect) – alexpeits Jan 28 '17 at 22:49
  • Duplicate? The linked question isn't about openpyxl. – stesch Jan 28 '17 at 22:52
  • you're right: 2 questions into one ! reopening. – Jean-François Fabre Jan 28 '17 at 22:53
  • This question is quite clearly outside the scope of Stack Overflow. This is just a simple variable assignment in Python and more than adequately covered by the documentation. – Charlie Clark Jan 29 '17 at 19:41

1 Answers1

1

The underscore is just a variable. Some languages give the underscore the special meaning to throw away/ignore the value. Python does not. But as the value isn't used here it is equivalent it.

The rest just sets the value of the sheet's cell to the column letter. 0 = A, 1 = B, …

stesch
  • 7,202
  • 6
  • 47
  • 62