Skip to content
క
kagitha
/
quiz
/
python-type-hints
Subscribe
Index
⌘K
JAVA NOTEBOOK · QUIZ 28 · BEGINNER
Python type hints for Java developers
QUESTION 01 / 04
def double(n: int) -> int: return n * 2. What does double("ha") do when you run it?
A
Raises a TypeError
B
Returns "haha"
C
Won't compile
D
Returns 0
SCORE SO FAR · 0 / 0
Share this quiz ↗
def double(n: int) -> int: return n * 2. What does double("ha") do when you run it?
— Returns "haha". Python doesn't enforce hints at runtime. The string is multiplied by 2, giving "haha". A type checker like mypy would flag the call before you run it.
Which hint means "a string, or None", like Java's Optional<String>?
— str | None. str | None (or Optional[str] in older code) says the value may be None, and a type checker will make callers check for it.
What is the Python hint for Java's Map<String, Integer>?
— dict[str, int]. Since Python 3.9 you can write dict[str, int] with the built-in name. Older code imports Dict from typing.
Why do type hints matter more in AI and web libraries?
— Libraries like Pydantic, FastAPI and agent frameworks read them to validate data and describe tools. These libraries inspect hints at runtime. Pydantic validates fields, FastAPI parses requests, and agent frameworks build tool schemas from hints and docstrings.
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