menu

Python Control Structures

Python Control Structures - Important Points


26. Which of the following statements is used to add an element to the end of a list in Python?

A. list.add(element)

B. list.insert(index, element)

C. list.append(element)

D. list.push(element)

Discuss Work Space

Answer: option c

Explanation:

The append() method is used to add an element to the end of a list in Python.

27. Which of the following statements is used to check if a value is in a list in Python?

A. value in list

B. list.contains(value)

C. list.include(value)

D. value.exists(list)

Discuss Work Space

Answer: option a

Explanation:

The in operator is used to check if a value is in a list in Python.

28. Which of the following statements is used to check if a key is in a dictionary in Python?

A. key in dictionary

B. dictionary.contains(key)

C. dictionary.include(key)

D. key.exists(dictionary)

Discuss Work Space

Answer: option a

Explanation:

The in operator is used to check if a key is in a dictionary in Python.

29. Which of the following statements is used to loop through a dictionary in Python?

A. for key in dictionary:

B. for value in dictionary:

C. for item in dictionary:

D. for key, value in dictionary.items():

Discuss Work Space

Answer: option d

Explanation:

The items() method is used to loop through a dictionary in Python.

30. Which of the following statements is used to break out of nested loops in Python?

A. continue

B. pass

C. break

D. exit

Discuss Work Space

Answer: option c

Explanation:

The break statement is used to break out of nested loops in Python.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now