exam questions

Exam PCEP-30-02 All Questions

View all questions & answers for the PCEP-30-02 exam

Exam PCEP-30-02 topic 1 question 26 discussion

Actual exam question from Python Institute's PCEP-30-02
Question #: 26
Topic #: 1
[All PCEP-30-02 Questions]

Which one of the lines should you put in the snippet below to match the expected output?
Expected output:

Code:

  • A. reverse(list)
  • B. list.reversed()
  • C. list.reverse()
  • D. reversed(list)
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Mohamed_Ali_Mhimdi
3 weeks, 2 days ago
Selected Answer: C
A. reverse(list): This is incorrect because reverse() is not a standalone function; it is a method of the list object. B. list.reversed(): This is incorrect because reversed() is not a method of the list object. Instead, reversed(list) returns an iterator, not a modified list. C. list.reverse(): This is correct. The reverse() method reverses the list in place, modifying the original list. D. reversed(list): This is incorrect because reversed(list) returns an iterator, not a modified list. To get a reversed list, you would need to convert the iterator to a list, e.g., list(reversed(list)).
upvoted 2 times
...
hovnival
1 month, 2 weeks ago
Selected Answer: C
The correct answer is: C. list.reverse() Explanation: list.reverse(): This is the correct method to reverse a list in place (modifies the original list). It doesn't return a new list but instead reverses the list itself. The expected output [4, 1, 7, 2, 'A'] matches this behavior. Why not the other options? A. reverse(list): This is invalid syntax; there's no standalone function called reverse. B. list.reversed(): This is incorrect as list objects do not have a method named reversed(). D. reversed(list): This returns an iterator, not a list. To achieve the desired effect, you'd need to convert the iterator back to a list using list(reversed(list)). Correct Code: list = ['A', 2, 7, 1, 4] list.reverse() print(list)
upvoted 3 times
...
Nfyughguygjhg
2 months ago
Selected Answer: A
c is correct answer
upvoted 1 times
...
christostz03
5 months, 2 weeks ago
c is correct answer
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago