-4

Is there any way to do this javascript code in python syntax:

var x = 1;
x++;

without:

x=1
x=x+1
  • What's wrong with `x=x+1`? – Julien Apr 15 '22 at 19:06
  • 3
    Isn’t it easier to find this information on the web instead spending time to ask a question? That’s like sending a regular mail instead of email because you forgot Wi-Fi password – nicael Apr 15 '22 at 19:14
  • no, python does not have a unary increment operator – juanpa.arrivillaga Apr 15 '22 at 19:21
  • It's worth mentioning that the Javascript `x++` expression has a value (specifically, the value of x after incrementing it) and the Python assignment statements do not. Use the walrus operator `(x:=x+1)` if you need a Python3.8+ assignment expression which has this value. – Michael Ruth Apr 15 '22 at 20:00

1 Answers1

2

No, in Python you can only do this:

x += 1

or in alternative

x = x+1
FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28