+ 2

Why is the answer '22'

>>> "2" + "2" '22'

21st Sep 2017, 4:03 PM
MelioCurry
MelioCurry - avatar
9 Answers
+ 4
You're more than welcome Stephen! Don't give up and be patient with programming. Trust me, ALL of us went through this process also, and it's certainly confusing/difficult in the beginning. However, just like most things that are worth it in life, if you stick with it and practice, you'll become great at it, but just remember that it does take time. It's similar to learning how to play an instrument. At first you're clunky and the notes/theory/etc... doesn't make sense. The more you practice though, the more effortless it becomes and the more you understand. Eventually, you're able to play music easily and are able to hear music & break it down easily.
21st Sep 2017, 4:21 PM
AgentSmith
+ 6
Because they're strings, not integers. You're just concat'ing two strings together. 2 and "2" are two different things. One is an actual integer number, and the other is just a string of text that happens to have a number in it, but is not treated as a number.
21st Sep 2017, 4:05 PM
AgentSmith
+ 6
The quotes is what is making that a string instead of an integer. >>>> 2 + 2 4 >>>> "2" + "2" 22
21st Sep 2017, 4:13 PM
AgentSmith
+ 5
(I dont know python but I'm guesz ) you write the number as string :)
21st Sep 2017, 4:20 PM
AL.The.Flame!
AL.The.Flame! - avatar
+ 3
so how are you gonna differentiate between integers and strings
21st Sep 2017, 4:12 PM
MelioCurry
MelioCurry - avatar
+ 3
thank you very much netkos ent am a beginner and am finding things very hard
21st Sep 2017, 4:19 PM
MelioCurry
MelioCurry - avatar
+ 3
It's my pleasure Stephen. I really do wish you the best of luck and hope it goes as smooth as possible! :) As an added note, bookmark this site: www.stackoverflow.com During my learning process, and even during my career, that site has been priceless when I've ran into issues and couldn't figure it out myself. If you've attempted to try something to no avail, it never hurts to consult the programmers of the world. We're all a team.
21st Sep 2017, 5:22 PM
AgentSmith
+ 1
thank you my hero
21st Sep 2017, 4:28 PM
MelioCurry
MelioCurry - avatar
0
thank you very much netkos I really appreciate your aid and hospitality
21st Sep 2017, 6:57 PM
MelioCurry
MelioCurry - avatar