Is it possible to assign a value and increment an assigned value on the same line in Python?
Something like that:
x = 1 a = x b = (x += 1) c = (x += 1) print a print b print c >>> 1 >>> 2 >>> 3
Edit: I need this in the context where I create an Excel sheet:
col = row = 1 ws.cell(row=row, column=col).value = "A cell value" ws.cell(row=row, column=(col += 1)).value = "Another cell value" ws.cell(row=row, column=(col += 1)).value = "Another cell value"
Edit 2: Solution: This is not possible, but I created an easy fix:
col = row = 1 def increment_one(): global col col += 1 return col ws.cell(row=row, column=col).value = "A cell value" ws.cell(row=row, column=increment_one()).value = "Another cell value" ws.cell(row=row, column=increment_one()).value = "Another cell value"
python
Vingtoft
source share