Free PCAP Data Structure Questions and Answers

0%

Which data structure does not allow duplicate elements?

Correct! Wrong!

Sets in Python do not allow duplicate elements.

What will be the output of the following code?br my_dict = {""name"": ""John"", ""age"": 30}br print(my_dict.get(""address"", ""Not found""))

Correct! Wrong!

The get method returns the specified default value if the key is not found in the dictionary.

Which of the following is true about tuples?

Correct! Wrong!

Tuples are immutable and can have duplicate elements.

Which method would you use to add an item to the end of a list in Python?

Correct! Wrong!

The append() method adds an item to the end of a list.

What is the correct syntax to create a tuple in Python?

Correct! Wrong!

Tuples in Python are created using parentheses.

What will be the result of the following code?br my_set = {1, 2, 3}br my_set.add(2)br print(my_set)

Correct! Wrong!

Sets do not allow duplicate elements, so adding an existing element does not change the set.

Which data structure is used to store a sequence of items that are ordered and changeable in Python?

Correct! Wrong!

Lists in Python are ordered, mutable sequences used to store collections of items.

How do you access the value associated with a specific key in a dictionary?

Correct! Wrong!

Values in a dictionary are accessed using square brackets with the key inside.

How do you check if a key exists in a dictionary?

Correct! Wrong!

The in keyword is used to check if a key exists in a dictionary

Which method would you use to combine two dictionaries in Python 3.9 or later?

Correct! Wrong!

The | operator is used to merge two dictionaries in Python 3.9 and later.

How can you remove the last item from a list?

Correct! Wrong!

The pop() method removes and returns the last item from a list.

Premium Tests $49/mo
FREE June-2024