0
a = 90
z  =0
z =a+1
print(z)

# I want do the both steps in one step but I am getting syntax error 
a = 90
z = a++
print(z)

**error 
    z = a++**

          ^
SyntaxError:
 invalid syntax

Can anyone explain why? And how to do the increment using ++?

m00am
  • 5,910
  • 11
  • 53
  • 69

2 Answers2

1

a++ does not support in python. Such as integers are immutable in python. z = a++ is invalid syntax. you can use a++ as a += 1.

 a = 90
 a+= 1
 z = a
 print(z)
sameera lakshitha
  • 1,925
  • 4
  • 21
  • 29
0

I don't believe there is x++ inpython. I know how it is used, and how it adds one to a number, but python does not support this. So instead you should use x+=1. That's fixing your syntax error. But for your question about doing it in one step, do this:

a = 90
z = a + 1

This works, but using x++ is not supported in python and is not more effective tha simply adding one to a and assigning it to z.

Ethanol
  • 370
  • 6
  • 18