Tags
python , ++
Asked 3 years ago
19 Sep 2021
Views 541
River

River posted

Is ++ allowed in Python?

Is ++ allowed in Python?
ruby-rails

ruby-rails
answered Sep 19 '21 00:00

++ is not allowed in Python.
in Python , you can use + sign to plus arithmetic operation.
so what if use ++ is in Python ?

x=1
x++

in use ++ operator in the Python , will give you error :
so above code give error like this below :

 x++
      ^
SyntaxError: invalid syntax


so what is alternative of ++ in Python ?
1.
=+ is used to add given number
x=+y means x=x+y

x=1
x=+1
print(x)

it will print 2 in above code

2.
+ is used to add given number
x=x+y will add x and y and set sum of x and y to x

x=1
x=x+1
print(x)

it will print 2 in above code

Post Answer