Review of python book and some other thoughts
It was mentioned by TechDirt in their reporting on an absurd copyright case (so, pretty normal).
The strange choice of the author to use identation to mark borders between paragrafs when indents are very important in python. He cud just have used newlines to do that.
The code is not easily copyable. If one tries, one gets spaces between every character or so like this: >>>cho i c e = ’ham’. This seems to be due to the font used.
Sometimes the examples are not clearly enuf explained. For instance, elif is explained as an “optional condition”, which is not all that clear. Fortunately, this is not much of a problem if one has an IDE ready to test it. For the record, elif works as an alternative condition if the first one isnt true. Ex.:
a = 1
b = 2
c = 3
if a == 1:
print "a holds"
elif b == 2:
print "b holds and a doesnt"
elif c == c:
print "neither a or b holds, but c does"
>>a holds
and:
a = 0
b = 2
c = 3
if a == 1:
print "a holds"
elif b == 2:
print "b holds and a doesnt"
elif c == c:
print "neither a or b holds, but c does"
>>b holds and a doesnt
lastly:
a = 0
b = 4
c = 3
if a == 1:
print "a holds"
elif b == 2:
print "b holds and a doesnt"
elif c == c:
print "neither a or b holds, but c does"
>>neither a or b holds, but c does
Note how the order of the elif's matter. An elif only activates when all the previous if's and elif's failed.
Python apparently does not understand how to add numbers and strings. So things like:
a = "string"
b = 1
print a+b
gives an error. It seems to me that one shud just have python autoconvert numbers to strings (using str function), just as python converts integers to floats when adding such two objects together. Perhaps this has changed in python 3ff. Im running 2.7.