Bird
0
0

You have two custom modules: math_ops.py with def add(a,b): and string_ops.py with def add(a,b):. How can you use both add functions in one script without name conflict?

hard📝 Application Q9 of 15
Python - Modules and Code Organization
You have two custom modules: math_ops.py with def add(a,b): and string_ops.py with def add(a,b):. How can you use both add functions in one script without name conflict?
AImport modules and call functions with module prefix like math_ops.add() and string_ops.add()
BImport both functions directly and call add() without prefix
CRename one module file to avoid conflict
DUse from module import * for both modules
Step-by-Step Solution
Solution:
  1. Step 1: Understand name conflicts

    Importing functions with same name directly causes conflict.
  2. Step 2: Use module prefixes to avoid conflict

    Import modules and call functions as math_ops.add() and string_ops.add().
  3. Final Answer:

    Import modules and call functions with module prefix like math_ops.add() and string_ops.add() -> Option A
  4. Quick Check:

    Use module prefix to avoid name conflicts [OK]
Quick Trick: Use module.function() to avoid name clashes [OK]
Common Mistakes:
  • Importing functions directly causing overwrite
  • Renaming files unnecessarily
  • Using star imports causing conflicts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes