Start with an array of integers, 1 through 5. First, square all the elements in the array. Then, sum all the elements of the squared array.
Python Language Features Interview Questions
Explain the difference between the following quoting in Python:
my_string = 'the cat sat on the mat'
my_string = "the cat sat on the mat"
my_string = """the cat sat on the mat"""
my_string = '''the cat sat on the mat'''
Define the following object oriented concepts:
- Class, object (and the difference between the two)
- Instantiation
- Method (as opposed to, say, a C function)
- Static methods and classes
- Destructor/finalizer
- Inheritance
- Encapsulation
- Multiple inheritance (and give an example)
- Abstract class
- Interface/protocol (and different from abstract class)
- Method overriding
- Method overloading (and difference from overriding)
- Polymorphism (without resorting to examples)
- Method visibility (e.g. public/private/other)
Explain the difference between method overloading and method overriding
What is __init__.py? Give an example of where you would use it.
Explain what a list comprehension is and write some code that illustrates an example use.
Explain the difference between a tuple and a list and give an example of where you would use each.
Explain what the following Python code does:
phrase = 'hello mommy'
print phrase[:4] + phrase[4:]
Write one line of readable Python code that will print the sum the integers from 1 to 100