Q1. if x = [1, 2, 5, 3, 4], what will be the output of print(x[0:3:2])?
- [1, 5, 4]
- [1, 5]
- [1, 2, 5, 3, 4]
- List index out of range exception!
Q2. What is the difference between a method and a function in Python?
- Functions can be called only by its name but methods can not be called by its name only.
- we don’t need a class to define a function but methods are defined inside a class.
- Functions are independent entities in a program while methods are dependent on the class they belong to.
- All of the above.
Q3. What will be the output of following code:
1 2 3 |
x = [10, 20, 30, 40] x += [10] print(x) |
- [20, 30, 40, 50]
- [10, 20, 30, 40, 10]
Q4. What will be the output of following code:
1 2 3 |
def fun(x = 3, y): print(x, y) fun(2) |
- 3 2
- 2 2
- 2 3
- SyntaxError
Q5. Which of the following is true when you open a file using with keyword?
- File reading and writing are faster using the with statement.
- The file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.
- You need not to handle exception anymore in the whole script.
Q6. A class can serve as base class for many derived classes.
- True
- False
Q7. The following code will throw an error.
1 2 3 |
def fun(**x): print(x[a]) fun(a=1, b=2, c=3) |
- True
- False
Q8. Which of the following statement will create a variable of string type?
- a = ”’AILearner”’
- a = “AILearner”
- a = ‘AILearner’
- All of the above.