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 9 discussion

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

What will be the output of the following code snippet?

  • A. [1, 3, 5, 7, 9]
  • B. [8, 9]
  • C. [1, 2, 3]
  • D. [1, 2]
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
hovnival
1 month, 2 weeks ago
Selected Answer: A
The output of the code snippet is: [1, 3, 5, 7, 9] Explanation: a[::2] uses Python slicing syntax: The first : indicates the starting point (default is the beginning of the list). The second : indicates the stopping point (default is the end of the list). The 2 after the second colon is the step size, which means it skips every second element. Starting from the first element (1), it selects every second element: 1, 3, 5, 7, 9.
upvoted 2 times
...
megan_mai
5 months, 2 weeks ago
Selected Answer: A
a = [1,2,3,4,5,6,7,8,9] print(a[::2]) >> printing the whole list a by the step 2 >> a[0], a[2], a[4], a[6], a[8], remeber to start counting from 0
upvoted 3 times
...
christostz03
5 months, 2 weeks ago
a is the correct answer
upvoted 1 times
...
froster02
6 months, 3 weeks ago
[start : stop : step] inclusive, exclusive respectively
upvoted 1 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