PYTHON REVISION
1. Python was created by:
A) Dennis Ritchie C) James Gosling
B) Guido van Rossum D) Bjarne Stroustrup
2. Which of these is a valid file extension for Python files?
A) .java C) .txt
B) .py D) .pyt
3. Python is a(n) _______ language.
A) Compiled C) Interpreted
B) Assembled D) Machine-level
4. Which keyword is used to define a function?
A) func C) function
B) def D) define
5. What is the output of print(type(3.5))?
A) <class 'int'> C) <class 'str'>
B) <class 'float'> D) <class 'complex'>
6. What is the result of 10 // 3?
A) 3.33 C) 4
B) 3 D) Error
7. Which of the following is not a valid identifier?
A) my_var C) data_1
B) 1data D) _value
8. What does len("Python") return?
A) 5 C) 7
B) 6 D) Error
9. Which symbol is used to comment in Python?
A) // C) #
B) /* */ D) <!-- -->
10. Which function returns the memory address of an object?
A) addr() C) address()
B) id() D) mem()
11. What is the output of bool(0)?
A) True C) 0
B) False D) Error
12. Which operator is used for exponentiation?
A) ^ C) *
B) ** D) ^^
13. What will print(10 % 3) output?
A) 3 C) 0
B) 1 D) 10
14. The in keyword is a:
A) Logical operator C) Bitwise operator
B) Membership operator D) Comparison operator
15. Which data type is immutable?
A) List C) Tuple
B) Dictionary D) Set
16. The keyword used to handle exceptions is:
A) handle C) trap
B) try D) except
17. The range(5) function produces:
A) 0 1 2 3 4 C) 5 numbers from 1
B) 1 2 3 4 5 D) None
18. Which of the following creates a list?
A) (1,2,3) C) [1,2,3]
B) {1,2,3} D) <1,2,3>
19. What does break do in a loop?
A) Skips one iteration C) Restarts the loop
B) Ends the loop immediately D) None
20. Which function converts string to integer?
A) str() C) int()
B) float() D) chr()
21. == compares ________, while is compares ________.
A) values, memory locations C) strings, integers
B) memory locations, values D) numbers, objects
22. What will list("abc") return?
A) "abc" C) ['a', 'b', 'c']
B) ['abc'] D) Error
23. Which function reads user input in Python?
A) read() C) get()
B) input() D) scanf()
24. Which statement is true about Python lists?
A) Immutable C) Constant
B) Mutable D) Static
25. Which function gives number of elements in a list?
A) length() C) count()
B) len() D) size()
26. What will "Python".lower() return?
A) PYTHON C) Python
B) python D) None
27. Which keyword is used to create a class?
A) def C) class
B) function D) obj
A) True C) Error
[Link]
B) What is printed by print(2 == 2.0)? D) None
29. What is the output of 3 > 2 and 2 > 5?
A) True C) Error
B) False D) None
30. The default return value of a Python function (if no return used) is:
A) 0 C) Empty string
B) None D) False
31. What will print("a" * 3) output?
A) a C) Error
B) aaa D) None
32. Which of these defines an empty dictionary?
A) [] C) {}
B) () D) set()
33. Which function removes and returns last element of list?
A) remove() C) pop()
B) del() D) delete()
34. What will happen if you use continue in a loop?
A) Loop ends C) Syntax error
B) Loop skips rest of block for current iteration D) None
35. The self keyword in Python refers to:
A) Current module C) Parent class
B) Current class instance D) Global variable
36. In Python, functions inside a class are called:
A) Functions C) Instances
B) Methods D) Variables
37. What does @staticmethod do?
A) Makes function static (no self) C) Defines private method
B) Adds method to global scope D) None
38. open("[Link]", "r") opens a file in:
A) Write mode C) Append mode
B) Read mode D) Binary mode
39. Which method is used to read entire file content?
A) read() C) readlines()
B) readline() D) readall()
40. To handle a specific exception, we use:
A) except Exception C) catch
B) except <type> D) try all
41. What is lambda used for?
A) Loop creation C) Class creation
B) Anonymous function D) Exception handling
42. Which module is used for mathematical operations?
A) statistics C) random
B) math D) numeric
43. The output of list(range(2,10,2)) is:
A) [2,4,6,8] C) [2,10]
B) [2,3,4,5,6,7,8,9] D) None
44. What does finally block do?
A) Executes only when error occurs C) Never executes
B) Executes always D) Executes if no exceptio
45. __init__ method is used to:
A) Delete object C) Call super class
B) Initialize object D) None
46. Which of the following creates a set?
A) [1,2,3] C) (1,2,3)
B) {1,2,3} D) <1,2,3>
47. Sets in Python are:
A) Ordered C) Immutable and Ordered
B) Mutable and Unordered D) Static
48. What does strip() method do?
A) Removes spaces from both ends C) Removes tabs only
B) Removes middle spaces D) Deletes variable
49. What keyword creates a generator?
A) generate C) return
B) yield D) gen
50. Which function is used to find length of dictionary?
A) len() C) length()
B) count() D) total()
51. Which method in a class is automatically called when an object is created?
A) __start__() C) __init__()
B) __new__() D) __create__()
52. In OOP, data hiding is achieved using:
A) public variables C) class variables only
B) variables with double underscores D) constants
53. What will isinstance(obj, ClassName) return?
A) True if obj is an instance of ClassName C) Checks if obj is callable
B) False always D) Error
54. Which of the following correctly opens a file for writing (overwriting)?
A) open("[Link]", "r") C) open("[Link]", "w")
B) open("[Link]", "a") D) open("[Link]", "x")
55. Which method reads one line at a time from a file?
A) read() C) readlines()
B) readline() D) nextline()
56. To ensure a file is properly closed even if an error occurs, use:
A) try-finally C) exit()
B) only try D) return
57. Which keyword is used to raise exceptions manually?
A) error C) raise
B) throw D) except
58. Which exception type handles any error in Python?
A) Exception C) BaseError
B) IOError D) Runtime
59. The map() function returns:
A) A list directly C) A dictionary
B) An iterator D) A string
60. The filter() function:
A) Filters even numbers automatically C) Works only on strings
B) Filters elements using a function returning D) Sorts a list
True/False
PREDICT THE OUTPUT QUESTIONS
1. 2.
a = [1,2,3] x = "Python"
b=a print(x[::-1])
[Link](4)
print(a)
3. 4.
def add(a, b=2): for i in range(3):
return a + b print(i, end=' ')
print(add(3)) else:
print("Done")
5. def f(x=[]):
[Link](1) 6.
return x class Student:
print(f(), f()) def __init__(self, name):
[Link] = name
s = Student("Asha")
print([Link])
7. 8.
f = open("[Link]", "w") try:
[Link]("Hello") x = 10 / 0
[Link]() except ZeroDivisionError:
f = open("[Link]", "r") print("Error")
print([Link]()) finally:
print("Done")
9. 10.
nums = [1, 2, 3, 4] def outer():
print(list(map(lambda x: x**2, nums))) x=5
def inner():
nonlocal x
x += 1
return x
return inner()
print(outer())
CODE CORRECTION QUESTIONS
1. 2.
if x = 10: for i in range(1,5)
print("Ten") print(i)
3. 4.
print("Sum is"+5) def add(a,b)
return a+b
5. 6.
list = [1,2,3] class Car
print(list[3]) def __init__(self, brand):
[Link] = brand
7. 8.
f = open("[Link]", "r") try:
[Link]("Hello") print(10/0)
else:
print("Success")
9. 10.
def square(x): nums = [1,2,3,4]
return x*x result = filter(x%2==0, nums)
print(list(result))
CODING QUESTIONS
1. Write a program to check if a number is even or odd.
2. Program to find factorial of a number.
3. Program to count vowels in a string.
4. Program to check palindrome.
5. Program to print Fibonacci series up to n terms.
6. Program to find maximum number in a list.
7. Create a class Employee with attributes name and salary and display them.
8. Write a program to copy contents of one file to another.
9. Program to handle division by zero.
10. Program using map() to convert list of strings to integers.
11. Program using filter() to extract even numbers from a list.
6. Program using lambda and reduce() to find product of list elements.