Could someone please explain the following behaviour difference?  class a():     pass class b(a):     pass   In Python2:  &gt;&gt;&gt; isinstance(b(),type(a())) True &gt;&gt;&gt; isinstance(a(),type(b())) True   In Python3:  &gt;&gt;&gt; isinstance(b(), type(a())) True &gt;&gt;&gt; isinstance(a(), type(b())) False
10842
What is the difference between old style and new style classes in Python?  When should I use one or the other?
1704
This has always confused me. It seems like this would be nicer:  my_list = ["Hello", "world"] print(my_list.join("-")) # Produce: "Hello-world"   Than this:  my_list = ["Hello", "world"] print("-".join(my_list)) # Produce: "Hello-world"   Is there a specific reason it is like this?
1022
The following code works as expected in both Python 2.5 and 3.0:  a, b, c = (1, 2, 3)  print(a, b, c)  def test():     print(a)     print(b)     print(c)    # (A)     #c+=1       # (B) test()   However, when I uncomment line (B), I get an UnboundLocalError: 'c' not assigned at line (A). The values of a and b are printed correctly. This has me completely baffled for two reasons:   Why is there a runtime error thrown at line (A) because of a later statement on line (B)? Why are variables a and b printed as expected, while c raises an error?   The only explanation I can come up with is that a local variable c is created by the assignment c+=1, which takes precedent over the "global" variable c even before the local variable is created. Of course, it doesn't make sense for a variable to "steal" scope before it exists.  Could someone please explain this behavior?
92805
I have a class A and another class that inherits from it, B. I am overriding a function that accepts an object of type A as a parameter, so I have to accept an A. However, I later call functions that only B has, so I want to return false and not proceed if the object passed is not of type B.  What is the best way to find out which type the object passed to my function is?
5893
What is the difference between    a parameter passed by reference a parameter passed by value?   Could you give me some examples, please?
98138
In Python, I can do:  &gt;&gt;&gt; list = ['a', 'b', 'c'] &gt;&gt;&gt; ', '.join(list) 'a, b, c'   Is there any easy way to do the same when I have a list of objects?  &gt;&gt;&gt; class Obj: ...     def __str__(self): ...         return 'name' ... &gt;&gt;&gt; list = [Obj(), Obj(), Obj()] &gt;&gt;&gt; ', '.join(list) Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: sequence item 0: expected string, instance found   Or do I have to resort to a for loop?
14089
I'm creating a function where I need to pass an object so that it can be modified by the function. What is the difference between:  public void myFunction(ref MyClass someClass)   and  public void myFunction(out MyClass someClass)   Which should I use and why?
685
I have seen this mentioned a few times and I am not clear on what it means. When and why would you do this?   I know what interfaces do, but the fact I am not clear on this makes me think I am missing out on using them correctly.   Is it just so if you were to do:  IInterface classRef = new ObjectWhatever()   You could use any class that implements IInterface? When would you need to do that? The only thing I can think of is if you have a method and you are unsure of what object will be passed except for it implementing IInterface. I cannot think how often you would need to do that.   Also, how could you write a method that takes in an object that implements an interface? Is that possible?
23113
What's the difference?  What are the advantages / disadvantages of tuples / lists?
6413
When programming interfaces, I've found I'm doing a lot of casting or object type conversion.  Is there a difference between these two methods of conversion?  If so, is there a cost difference or how does this affect my program?  public interface IMyInterface {     void AMethod(); }  public class MyClass : IMyInterface {     public void AMethod()     {        //Do work     }      // Other helper methods.... }  public class Implementation {     IMyInterface _MyObj;     MyClass _myCls1;     MyClass _myCls2;      public Implementation()     {         _MyObj = new MyClass();          // What is the difference here:         _myCls1 = (MyClass)_MyObj;         _myCls2 = (_MyObj as MyClass);     } }   Also, what is "in general" the preferred method?
109666
What is the best way to copy a list? I know the following ways, which one is better? Or is there another way?  lst = ['one', 2, 3]  lst1 = list(lst)  lst2 = lst[:]  import copy lst3 = copy.copy(lst)
9167
If class B and class C extend class A and I have an object of type B or C, how can I determine of which type it is an instance?
2603
I have been bitten by something unexpected recently. I wanted to make something like that:  try :      thing.merge(iterable) # this is an iterable so I add it to the list except TypeError :      thing.append(iterable) # this is not iterable, so I add it   Well, It was working fine until I passed an object inheriting from Exception which was supposed to be added.  Unfortunetly, an Exception is iterable. The following code does not raise any TypeError:  for x in Exception() :     print 1   Does anybody know why?
91640
I have a model class:  class Person(db.Model):   first_name = db.StringProperty(required=True)   last_name = db.StringProperty(required=True)   I have an instance of this class in p, and string s contains the value 'first_name'. I would like to do something like:  print p[s]   and   p[s] = new_value   Both of which result in a TypeError.  Does anybody know how I can achieve what I would like?
33281
In terms of Java, when someone asks:      what is polymorphism?   Would overloading or overriding be an acceptable answer?  I think there is a bit more to it than that.   IF you had a abstract base class that defined a method with no implementation, and you defined that method in the sub class, is that still overridding?  I think overloading is not the right answer for sure.
93303
If I have the following code: MyType&lt;int&gt; anInstance = new MyType&lt;int&gt;(); Type type = anInstance.GetType();  How can I find out which type argument(s) &quot;anInstance&quot; was instantiated with, by looking at the type variable? Is it possible?
76838
Is there a way in Python to override a class method at instance level? For example:  class Dog:     def bark(self):         print "WOOF"  boby = Dog() boby.bark() # WOOF # METHOD OVERRIDE boby.bark() # WoOoOoF!!