If you think that Python is easy to read and understand then look
at the following snippets and see if you can forecast what they
will do. Number assignment should be simple enough:
from x1428 import e
a = 1428
b = 1428
c = a is b
print("1428 is 1428 = " + str(c)) #as we expected
print("All three are 1428") #just prove they are all the same
print(a)
print(b)
print(e)
c = e is a #are they the same?
print("What should c be, it is = " + str(c))
# the file x1428.py contains a single line, being:
# e = 1428
RevealAnd, just to compare, change the 1428 values to 14 in the test script and the imported file and try again
from x14 import e
a = 14
b = 14
c = a is b
print("14 is 14 = " + str(c)) #as we expected
print("All three are 14") #just prove they are all the same
print(a)
print(b)
print(e)
c = e is a #are they the same?
print("What should c be, it is = " + str(c))
# the file x14.py contains a single line, being:
# e = 14
Reveal
How is it a good choice that code that uses 14 as a constant behaves so differently to code that replaced that constant with 1428? Dictionaries are amazing,
x = {True: 'yes', 1: 'no',1.0: 'Really'} #create and initialize a dict
print(x)
Reveal
How complex can this one liner be? And wouldn't you expect the output to be simple:
x = (n for n in [1,2,3])
print(2 in x)
print(2 in x)
RevealWhen even a print statement is not deterministic we have to question readability. There are so many more, I just like the few above examples. The reader will probably agree that these are not complex statements using esoteric features of the language. There are no decorators, list comprehensions, etc and even the generator is incredibly confusing. |