Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views1 page

5 Python MCQs Exam

The document contains a series of questions and multiple-choice answers related to Python programming concepts, including sets, list comprehensions, generators, and error types. It addresses how to create sets, the purpose of the Counter class, and the differences between lists and generators. Additionally, it discusses common use cases for generators and identifies various types of errors in code snippets.

Uploaded by

sait_80597
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

5 Python MCQs Exam

The document contains a series of questions and multiple-choice answers related to Python programming concepts, including sets, list comprehensions, generators, and error types. It addresses how to create sets, the purpose of the Counter class, and the differences between lists and generators. Additionally, it discusses common use cases for generators and identifies various types of errors in code snippets.

Uploaded by

sait_80597
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

50.

What are sets in A) Unordered collections of unique elements, B)


Python? Ordered collections of elements, C) Collections of
key-value pairs, D) Collections of lists
51. How do you create a set A) my_set = set(), B) my_set = {}, C) my_set = [], D)
in Python? my_set = set([])
52. What is the purpose of A) To count the occurrences of elements in an
the Counter class in iterable, B) To count the number of items in a list,
Python's collections C) To count the number of lines in a file, D) To count
module? the number of unique elements in a set
53. What is the difference A) Lists store all elements in memory at once, while
between a list and a generators produce elements on demand, B) Lists
generator? are immutable, while generators are mutable, C)
Lists are faster than generators, D) Generators are
only used for simple tasks
54. How can you use list A) By including a conditional expression within the
comprehensions to list comprehension, B) By using the filter() function,
filter elements from a C) By creating a new list and manually adding
list? elements, D) List comprehensions cannot be used
for filtering
55. What are some A) Processing large datasets, infinite sequences,
common use cases for and lazy evaluation, B) Creating simple loops, C)
generators in Python? Implementing data structures like stacks and
queues, D) Generating random numbers
56. What type of error does A) Syntax Error, B) Runtime Error
this code snippet have? (ZeroDivisionError), C) Semantic Error, D) No Error
x = 5; print(x); y = 2; z =
x / 0; print(z)
57. What type of error does A) Syntax Error, B) Runtime Error (IndexError), C)
this code snippet have? Semantic Error, D) No Error
numbers = [1, 2, 3];
print(numbers[3])
58. What type of error does A) Syntax Error, B) Runtime Error (IndexError), C)
this code snippet have? Semantic Error, D) No Error
my_list = [1, 2, 3];
my_list.append(4);
print(my_list.pop(5))
59. What type of error does A) Syntax Error, B) Runtime Error (RecursionError),
this code snippet have? C) Semantic Error, D) No Error
def factorial(n): if n ==
0: return 1; else: return
n * factorial(n); result =
factorial(5); print(result)
60. What type of error does A) Syntax Error, B) Runtime Error (IOError), C)
this code snippet have? Semantic Error, D) No Error
try: f =
open("myfile.txt", "r");
f.write("Hello!"); except
FileNotFoundError:
print("File not found.")
61. What type of error does A) Syntax Error, B) Runtime Error (KeyError), C)
this code snippet have? Semantic Error, D) No Error

You might also like