0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning β€” completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
T
3 months ago
Tanishacountry asked

Why does print(''5"+"3") gives 53?

Saujanya Poudel
Expert
yesterday

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 5 and 3 are 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!

Python
This question was asked as part of the Learn Python Basics course.