+ 5

[SOLVED]Are prefixes and postfixes used in python?

Are prefixes and postfixes like x++,++x,x--,--x, used in python? Or am I thinking of java and c++?

2nd Jul 2018, 7:01 PM
LONGTIE👔
LONGTIE👔 - avatar
7 odpowiedzi
+ 8
Nope, prefixes and postfixes are not available in Python. Prefixes will just represent operators, so: --x will be equal to x ++x will also be equal to x Postfixes will raise the SyntaxError exception.
2nd Jul 2018, 7:05 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 12
Adding to what Tom said: x += y ➡️ x = x + y x -= y ➡️ x = x - y x *= y ➡️ x = x * y x /= y ➡️ x = x / y x //= y ➡️ x = x // y x **= y ➡️ x = x ** y x %= y ➡️ x = x % y Same goes for bitwise operators: x &= y ➡️ x = x & y x |= y ➡️ x = x | y x ^= y ➡️ x = x ^ y And don't get it confused with: x != y ➡️ is x different than y ;)
2nd Jul 2018, 8:09 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 10
It is a bitwise XOR operator. It assumes True only when both arguments are of different boolean values: True ^ False == True True ^ True == False False ^ True == True False ^ False == False
2nd Jul 2018, 8:15 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
x += 1 x-=1 I guess(Not py pro)
2nd Jul 2018, 7:32 PM
Sad
Sad - avatar
+ 3
Kuba Siekierzyński x ^= y? what do you use that for
2nd Jul 2018, 8:11 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 3
Kuba Siekierzyński ok thanks for all the helpful answers
2nd Jul 2018, 8:16 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
Kuba Siekierzyński what should I use as a alternative?
2nd Jul 2018, 7:10 PM
LONGTIE👔
LONGTIE👔 - avatar