Why “cat” is not equal to “dog” in Python [duplicate]

Because python compares sequences (i.e. strings you have) sequentially by element values. “c” comes before “d” in Unicode, hence the result. To compare length, use len(a) == len(b) The motivation behind this – having sequential comparison of elements, you can sort sequences in sane way. I.e. sorting list of names alphabetically is just sorted(names_list). And … Read more

Logic behind sizeof operator [duplicate]

The compiler knows the size of all types, it has to or it would not be able to generate code correctly. This information is used by the sizeof operator. Also note that sizeof is not some function being called at runtime, it’s an operator that is fully evaluated during compilation.