

Python quizzes, interview questions and answers - xquizzes
http://xquizzes.com/programming/Python

======
dalke
Some of the answers are wrong, or reveal only a shallow understanding of
Python. For example:

> What is pickling and unpickling?

> Pickle module accepts any Python object and converts it into a string
> representation and dumps it into a file by using dump function, this process
> is called pickling. While the process of retrieving original Python objects
> from the stored string representation is called unpickling.

The first sentence is wrong. File objects, for example, cannot be pickled.
Also, in Python3, which makes a stronger distinction between a 'string' and
'bytes', a pickle returns bytes, not a string. Also, the pickle module can
pickle to/from bytes without touching a file.

For another example:

> How will you compare two lists?

> cmp(list1, list2) − Compares elements of both lists.

The answer is "list1 == list2", for most uses of 'compare'. The 'cmp' function
is no longer part of Python, and its use was a bit tricky.

For a third:

> What are the rules for local and global variables in Python?

> If a variable is defined outside function then it is implicitly global. If
> variable is assigned new value inside the function means it is local.

This is not correct. Consider:

    
    
        class Spam:
            x = 5
    

The variable x is neither defined in a function nor is a global variable.

Looking through the answers, I would discourage people from using this site.
It is better to read the Python documentation and FAQ.

