Skip to content
క
kagitha
/
quiz
/
python-collections
Subscribe
Index
⌘K
JAVA NOTEBOOK · QUIZ 20 · BEGINNER
Python list and dict for Java developers
QUESTION 01 / 04
How do you get the last item of a Python list called items?
A
items.get(items.size() - 1)
B
items[-1]
C
items.last()
D
items[len]
SCORE SO FAR · 0 / 0
Share this quiz ↗
How do you get the last item of a Python list called items?
— items[-1]. Negative indexes count from the end, so items[-1] is the last item and items[-2] the one before it.
user is a dict without an "email" key. What does user.get("email") return?
— None. d.get(key) returns None for a missing key, and d.get(key, default) returns your default. Only d[key] raises KeyError.
What does nums[1:3] give for nums = [10, 20, 30, 40]?
— [20, 30]. A slice starts at the first index and stops before the second, like subList(1, 3). The result is a new list.
After items = items.sort(), what is items?
— None. list.sort() sorts in place and returns None, so the assignment replaces your list with None. Call items.sort() on its own, or use items = sorted(items).
kagitha
Close
✕
Search everything — articles, videos, chapters, agents, books
01
AI
02
Java
03
System Design
04
Series
05
Manga
06
The Lab
07
Videos
08
Quizzes
09
Books
10
Resume