exam questions

Exam 98-381 All Questions

View all questions & answers for the 98-381 exam

Exam 98-381 topic 1 question 22 discussion

Actual exam question from Microsoft's 98-381
Question #: 22
Topic #: 1
[All 98-381 Questions]

You develop a Python application for your company.
A list named employees contains 200 employee names, the last five being company management. You need to slice the list to display all employees excluding management.
Which two code segments should you use? Each correct answer presents a complete solution. (Choose two.)

  • A. employees [1:-4]
  • B. employees [:-5]
  • C. employees [1:-5]
  • D. employees [0:-4]
  • E. employees [0:-5]
Show Suggested Answer Hide Answer
Suggested Answer: BE 🗳️
References: https://www.w3resource.com/python/python-list.php#slice

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
gargaditya
Highly Voted 4 years, 8 months ago
Answer is correct. 2 key point to remember: 1.indexing begins at 0 2.slicing-> [a:b] means start at 'a',go upto BUT NOT INCLUDING 'b' Hence,here employees are indexed 0 thru 199 Removing last 5 makes it 0 to 194 which is represented as [0:195] !!careful the 5 ids are 195,196,197,198,199 -5 -2 -1 3.further ,used concept of negative indexing 4.and [0:c] is same as [:c]
upvoted 5 times
...
print_HelloWorld
Most Recent 3 years, 1 month ago
CORRECT
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 ...