0

what does this line explaining the Zen of Python mean?

I mean the part after the greater than signs: Explicit is better than implicit: It is best to spell out exactly what your code is doing. This is why >>>>>>>> adding a numeric string to an integer requires explicit conversion, rather than having it happen behind the scenes, as it does in other languages.

28th Mar 2017, 12:08 AM
Fabian Salinas L
Fabian Salinas L - avatar
2 Answers
+ 20
Sometimes you must specifically tell the python interpreter that a string is a string, and an int is an int. print(str(807) + "abc") gives the output 807abc, or print("807" + "abc") yields the same. Where int is used with a string, it goes like this: print(int("807") + 3) would have the output 810, and print( "807" + 3) would not have been told string "807" is an int like 807. So that would be a TypeError between adding just "807" + 3, which is a string plus an int. In another language you might mix the two but with type errors if the string isn't an int. Remember you can use the type function too: print(type("807")) print(type(807)) print(type(int("807"))) print(type(str(807)))
28th Mar 2017, 1:28 AM
David Hutto
David Hutto - avatar
+ 3
Run a Python program with the only line being "4"+2 and hopefully you will understand. If not comment here and I will explain.
28th Mar 2017, 12:58 AM
Tob
Tob - avatar