Skip to content
క
kagitha
/
quiz
/
python-functions
Subscribe
Index
⌘K
JAVA NOTEBOOK · QUIZ 25 · BEGINNER
Python functions and keyword arguments
QUESTION 01 / 04
What happens if you define two Python functions with the same name but different parameters?
A
Python overloads them, like Java
B
The second definition replaces the first
C
A syntax error
D
Python picks one at random
SCORE SO FAR · 0 / 0
Share this quiz ↗
What happens if you define two Python functions with the same name but different parameters?
— The second definition replaces the first. Python has no method overloading. The name simply points to the latest function. Use default values and keyword arguments instead.
Given def summarize(text, max_words=50, style="plain"), how do you change only the style?
— summarize(doc, style="bullets"). Pass the argument by name. Keyword arguments let callers set only what they need, which is why Python rarely uses builders.
Inside a function, what is kwargs in def f(**kwargs)?
— A dict of the extra named arguments. **kwargs collects named arguments that don't match any parameter into a dict. *args collects extra positional arguments into a tuple.
Why is def add(msg, history=[]) a bug?
— The same list is created once and shared by every call. Defaults are created when the def runs, once. Every call that uses the default appends to the same list. Default to None and create the list inside.
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