0% found this document useful (0 votes)
2 views

Python

The document contains a series of multiple-choice questions related to Python programming concepts, including functions, data types, and methods. Each question provides four answer options, testing knowledge on topics such as lambda functions, docstrings, class attributes, and built-in functions. The questions cover a range of Python features and behaviors, aiming to assess the reader's understanding of the language.

Uploaded by

groovestudy46
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python

The document contains a series of multiple-choice questions related to Python programming concepts, including functions, data types, and methods. Each question provides four answer options, testing knowledge on topics such as lambda functions, docstrings, class attributes, and built-in functions. The questions cover a range of Python features and behaviors, aiming to assess the reader's understanding of the language.

Uploaded by

groovestudy46
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. What would this function return if we input 10?

>>> def make_incrementor(n):


… return lambda x: x + n
a. A list of values
b. A function
c. 10
d. 11

2. How would you print out the informal, readable string representation of an
object?
a. repr()
b. str()
c. print()
d. eval()

3. Which is an accepted way to write a docstring in Python?


a. def func ():
‘’ ‘’’ ‘’
This function does nothing
‘’ ‘’ ‘’
pass
b. def func ():
‘’
This function does nothing
‘’
pass
c. def func ():
#
This function does nothing
#
pass
d. def func(): #This function does nothing pass

4. Which of the following statement is NOT correct?


a. Lists are slower than tuples
b. Lists and tuples have the same methods.
c. An example use of a tuple would be to store a user's credentials.
d. Lists are mutable

5. What does the following statement do? os.unlink(filename)


a. It removes a file.
b. It removes the links of a file.
c. It removes a file descriptor of the given file.
d. It unlinks the file from the Python heap.

6. Which of the following does the use of the self keyword in Python represent?
a. The instance of the class
b. The class of an instance
c. The variables of an instance outside the class
d. The variables of an instance inside the class

7. Which function will access a class's immediate parents' methods and


attributes?
a. dir ()
b. super ()
c. classmethod ()
d. attr ()

8. What is true about a defaultdict?


a. It does not need to be initialized.
b. It will return a KeyError if the key is not found.
c. It will return False if the key is not found.
d. It will return the assigned default value if the key is not found.

9. How would you declare a variable a in Python?


a. a = 1
b. a = <int> 1
c. c int a = 1
d. let a = 1
10. What does the following program check? n=int(input("Enter number:"))
temp-n rev=0 while(n>0) dig=nX10 rev=rev*10+dig n-n//10 if(temp==rev):
return True else: return False
a. If a number is even
b. If a number is a palindrome
c. If a number is cubic
d. If a number is prime

11. What is used to access a class's attributes and methods?


a. def
b. self
c. attr
d. func

12. How would you print out a docstring in Python?


a. print(func.___repr___)
b. print(func._documentation___)
c. print(func. ___doc____)
d. print(func.___selfdoc___)

13. What does the pass statement do?


a. Nothing.
b. It exits the program.
c. It passes a codeblock to the next pointer.
d. It indicates that the program has executed successfully.

14. The following are examples of what? list(), map(), reduce()


a. Functional programming
b. Non-functional programming
c. Bulk operations
d. Stateful operations

15. Which of the following is an invalid type for the max() function?
a. str
b. list
c. tuple
d. queue
16. What does this function do? num = int(input("Enter a number: ")) xxx = 1 if
num < 0: print(" xxx does not exist for negative numbers") elif num == 0:
print("The xxx of @ is 1") else: for i in range(1, num + 1): XXX = xxx*i
a. It deletes negative numbers from lists.
b. It calculates factorials.
c. It inverts lists.
d. It performs list comprehension.

17. What does the repr() function return?


a. The bytecode of the function
b. The functions related to that function
c. The string representation of that function
d. The code of that function

18. What is the output of the code below? print(list(map(lambda n: n + n, (25,


15, 45))))
a. [25, 40, 60]
b. None
c. Map Object
d. [50, 30, 90]

19. What would you use the isinstance() function to check?


a. If one module is an instance of another
b. If one statement is an instance of another
c. If one conditional is an instance of another
d. If one value holds a particular data type

20. What would be the output of the code below?


for i in range(-11):
print(i)
a. The numbers 0 to -10
b. The numbers 0 to -11
c. Nothing
d. The numbers 0 to 10

21. How would you reverse a string?


a. str_reverse = string[:-1]
b. str_reverse = string.switch()
c. str_reverse = string[::-1]
d. str_reverse = reverse(string)

22. What is the output of the following code?


a = [1,2,3,5,6]
print(a[-1])

a. [1,2,3,5]
b. 1
c. IndexError
d. 6

You might also like