-
I'm surprised that
all({}), all([]), all(())are allTrue, while we all knowbool({}), bool([]), bool(())andany({}), any([]), any(())are all 'False'. What is the reason for the trueall({}), all([]), all(())? -
As for
a = [1, 2, 3]; b = a[:],a is bisFalse, while fora = (1, 2, 3); b = a[:],a is bisTrue(they share the same address). I understandaisbif setsb = a. But why still so when setb = a[:], just because tuple is immutable? -
If
s1, s2 = 'str', 'str',s1 is s2isTrue, buts is ''.join(('s','t','r'))isFalse. This fact has been known well but I don't understand very well. -
I read some posts on SO and also some tutorials by google concerning
__cmp__and rich comparisons, but I still didn't get why somebodies prefer rich comparisons than__cmp__. It looks more convenient to implement the comparison in just one__cmp__method enabling all of<, <=, ==, !=, >=, >work. Can anyone give some a concise and clear explanation?
vendredi 5 août 2016
Conditions in python [on hold]
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire