
In Python, the = symbol is used as the assignment operator. This is how we store a value in a variable.
It's a little bit like putting something into a box and giving that box a name. Let's look at an example to see how it works:
color1 = "blue"
print(color1)
color2 = "pink"
color1 = color2
print(color1)
print(color2)Here's what's happening step by step:
color1 = "blue": You create a variable calledcolor1and store the string"blue"in it. Think ofcolor1as a label stuck onto the box that has "blue" inside it.print(color1): This prints"blue"to the console becausecolor1currently points to"blue".color2 = "pink": You create another variable calledcolor2and store the string"pink"in it.color1 = color2: This is where the assignment operator shows its magic. You're telling Python to makecolor1store whatever valuecolor2currently holds, which is"pink". Now, bothcolor1andcolor2point to"pink". Think of it as removing "blue" from thecolor1box and adding whatever is in thecolor2box, which is "pink".print(color1): Prints"pink", becausecolor1is now storing the value"pink".print(color2): Also prints"pink", as expected sincecolor2hasn't changed.
Hope this clears things up! Feel free to reach out if you have any more questions or need further clarification.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer