
Hello! Understanding how Python treats different data types like numbers and strings is a common area of curiosity when starting out. Let's break it down.
When you write:
print("5" + "3")Here's what happens:
The numbers
5and3are actually inside quotation marks. So Python sees them as strings, not numbers.In Python, the
+operator behaves differently with strings. Instead of adding them as numbers, it concatenates or "glues" them together.This means
"5" + "3"becomes the text"53"because you're joining two pieces of text.
Contrast this with:
print(5 + 3) Here, 5 and 3 are numbers (because they're not enclosed in quotations), so Python adds them mathematically, resulting in 8.
Hope this clears things up for you! π Feel free to try out more examples or ask any follow-up questions if you're curious about anything else!
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
