Is there any difference between print 3 and print '3' in Python ?

Dave Angel d at davea.name
Mon Mar 26 14:11:03 CEST 2012


On 03/26/2012 07:45 AM, redstone-cold at 163.com wrote:
> I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ?

This is a non-question.  The input is the same, the output is the same, 
what else matters?

On the other hand, if you want to dig deeper, there are lots of differences:

1) the former has a shorter source file
2) different C code is utilized inside the interpreter
3) different machine code executes
4) the temporary objects created have different id's and types
5) different execution times (by a trivial amount)
6) it takes different keystrokes to edit the two source files once you 
want to make it do something useful
7) the processor works a little harder on one than the other, possibly 
resulting in a different power consumption
8) different byte code is produced

Or you could be asking about Python version 3, in which case
1) the syntax error message points to a different character

-- 

DaveA




More information about the Python-list mailing list