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

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Mar 27 05:43:46 CEST 2012


On Mon, 26 Mar 2012 08:11:03 -0400, Dave Angel wrote:

> 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?

def fib1(n):
    if n == 0: return 0
    elif n == 1: return 1
    f2, f1 = 0, 1
    for _ in range(2, n+1):
        f2, f1 = f1, f2 + f1
    return f1

def fib2(n):
    if n == 0: return 0
    elif n == 1: return 1
    else: return fib2(n-1) + fib2(n-2)


Try calling fib1(35) and fib2(35). Still think only the input and output 
matter? :)


For the record, fib2(35) ends up making a total of 29860703 function 
calls, compared to 35 iterations for fib1.



-- 
Steven



More information about the Python-list mailing list