What is the difference between old style and new style classes in Python?

What is the difference between old style and new style classes in Python? When should I use one or the other? 8 s 8 From New-style and classic classes: Up to Python 2.1, old-style classes were the only flavour available to the user. The concept of (old-style) class is unrelated to the concept of type: … Read more

What are POD types in C++?

I’ve come across this term POD-type a few times. What does it mean? 9 s 9 POD stands for Plain Old Data – that is, a class (whether defined with the keyword struct or the keyword class) without constructors, destructors and virtual members functions. Wikipedia’s article on POD goes into a bit more detail and … Read more

Change column type in pandas

I want to convert a table, represented as a list of lists, into a pandas DataFrame. As an extremely simplified example: a = [[‘a’, ‘1.2’, ‘4.2’], [‘b’, ’70’, ‘0.03’], [‘x’, ‘5’, ‘0’]] df = pd.DataFrame(a) What is the best way to convert the columns to the appropriate types, in this case columns 2 and 3 … Read more

What are the differences between type() and isinstance()?

What are the differences between these two code snippets? Using type(): import types if type(a) is types.DictType: do_something() if type(b) in types.StringTypes: do_something_else() Using isinstance(): if isinstance(a, dict): do_something() if isinstance(b, str) or isinstance(b, unicode): do_something_else() 7 To summarize the contents of other (already good!) answers, isinstance caters for inheritance (an instance of a derived … Read more

Long vs Integer, long vs int, what to use and when?

Long is the Object form of long, and Integer is the object form of int. The long uses 64 bits. The int uses 32 bits, and so can only hold numbers up to ±2 billion (-231 to +231-1). You should use long and int, except where you need to make use of methods inherited from Object, such as hashcode. Java.util.collections methods usually use the boxed (Object-wrapped) versions, because they need to work for any Object, and … Read more