Python - Mock Interview Test
1. What is the correct syntax to output "Hello, World" in Python?
A. print("Hello, World")
B. echo("Hello, World")
C. println("Hello, World")
D. printf("Hello, World")
2. What is the correct way to create a list in Python?
A. list = [1, 2, 3]
B. list = (1, 2, 3)
C. list = {1, 2, 3}
D. list = <1, 2, 3>
3. How do you insert an item at the end of a list in Python?
A. list.append(5)
B. list.add(5)
C. list.push(5)
D. list.insert(5)
4. How do you declare a function in Python?
A. def function_name()
B. function function_name()
C. func function_name()
D. def function_name{}
5. What is the correct way to create a dictionary in Python?
A. dict = { "key1": "value1", "key2": "value2" }
B. dict = [ "key1": "value1", "key2": "value2" ]
C. dict = ( "key1": "value1", "key2": "value2" )
D. dict = < "key1": "value1", "key2": "value2" >
6. What will be the output of the following Python code?
print(3 * 3 / 2)
A. 4.5
B. 4
C. 5
D. Error
7. What is the correct syntax for a for loop in Python?
A. for i in range(5):
B. for i = 0 to 5:
C. for i in [0, 5]:
D. for i in 0..5:
8. Which of the following is a correct syntax for a while loop in Python?
A. while x > 5:
B. while (x > 5)
C. while x > 5 do:
D. while (x > 5) {
9. How do you check the type of an object in Python?
A. isinstance(x, type)
B. type(x)
C. type_of(x)
D. None of the above
10. How do you create a class in Python?
A. class MyClass:
B. class MyClass():
C. create class MyClass:
D. class MyClass[]:
11. What is the output of the following code: print(2 ** 3)?
A. 8
B. 6
C. 9
D. Error
12. How do you make a Python script executable?
A. chmod +x script.py
B. python script.py
C. ./script.py
D. all of the above
13. What function is used to get the length of a string in Python?
A. len()
B. length()
C. size()
D. count()
14. How do you import a module in Python?
A. import module_name
B. include module_name
C. import(module_name)
D. using module_name
15. How do you handle exceptions in Python?
A. try...except block
B. catch block
C. error...catch block
D. raise block
16. What is the correct syntax to create a set in Python?
A. set = {1, 2, 3}
B. set = [1, 2, 3]
C. set = (1, 2, 3)
D. set = <1, 2, 3>
17. What is the output of this Python expression: 10 // 3?
A. 3
B. 3.33
C. 3.0
D. 2
18. Which of the following is an immutable data type in Python?
A. tuple
B. list
C. set
D. dictionary
19. How do you define a class variable in Python?
A. variable_name = value
B. self.variable_name = value
C. class.variable_name = value
D. instance.variable_name = value
20. How do you check if a key exists in a dictionary in Python?
A. key in dict
B. dict.has_key(key)
C. dict.contains(key)
D. key in dict.keys()
Submit
Go Back