Q1. What will be the output of following code:
1 2 3 4 5 6 7 8 9 10 11 12 |
class A: def __iter__(self): self.a = 1 return self def __next__(self): x = self.a self.a += 1 return x a = A() myiter = iter(a) next(myiter) print(next(myiter)) |
- 3
- 1
- 2
- Error
Q2. The following code will throw an error.
1 2 3 4 |
def fun(*x): print(x[2]) fun("a", "b", "c") |
- True
- False
Q3. What will be the output of following code:
1 |
print(len(" TheAI "), len(" TheAI ".strip())) |
- 8 5
- 8 6
- 7 6
- 7 5
Q4. What will be the output of following code:
1 |
print(('AILearner')*3) |
- (‘AILearner’,’AILearner’,’AILearner’)
- AILearnerAILearnerAILearner
- (‘AILearner3’)
- Error
Q5. What will be the output of following code:
1 2 3 4 5 |
class Language: def get_lang(self, line='Python'): print(line) obj = Language() obj.get_lang('Java') |
- Python
- Java
- Java
Python - Python
Java
Q6. What will be the output of following code:
1 2 3 |
x = [1,2] x[3:4] = [3] print(x) |
- [1, 2, 3]
- [1, 3]
- [1, 2]
- Throws an error!
Q7. Which of the following data types can have only two values (either True or False)?
- integer
- Strings
- Boolean
- Float
Q8. What will be the output of print(2 * 3 ** 3 * 2)?
- 108
- 432
- 1458
- 36