Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Assignment & Unary Operators

Lesson 10 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

Assignment and Unary Operators

Assignment Operators

Assignment operators assign or update the value stored in a variable.

OperatorExampleEquivalent To
=x = 5direct assignment
+=x += 5x = x + 5
-=x -= 5x = x - 5
*=x *= 5x = x * 5
/=x /= 5x = x / 5
//=x //= 5x = x // 5
%=x %= 5x = x % 5
**=x **= 5x = x ** 5
&=, `\=, ^=`x &= 5bitwise-and-assign, etc.
>>=, <<=x >>= 1shift-and-assign
x = 10
x += 5   # 15
x *= 2   # 30
x //= 4  # 7
print(x)

---

Unary Operators

A unary operator acts on a single operand.

OperatorMeaningExample
+Unary plus (no effect on sign)+5 -> 5
-Unary minus (negation)-5 -> -5
notLogical NOTnot True -> False
~Bitwise NOT (complement)~5 -> -6
a = 5
print(-a)      # -5
print(+a)      # 5
print(not a)    # False (5 is truthy)
print(~a)      # -6  (bitwise complement: -(a+1))

Increment/Decrement — Note

Python has no ++ or -- operators (unlike C/Java). Use += / -= instead.

count = 0
count += 1   # equivalent to count++ in C
count -= 1   # equivalent to count-- in C