Bird
0
0

How can you import the 'pathlib' module with alias 'pl' and use it to get the current working directory as a string?

hard📝 Application Q9 of 15
Python - Modules and Code Organization
How can you import the 'pathlib' module with alias 'pl' and use it to get the current working directory as a string?
Aimport pl as pathlib print(pl.Path.cwd())
Bimport pathlib as pl print(str(pl.Path.cwd()))
Cimport pathlib as pl print(pl.getcwd())
Dimport pathlib print(pl.Path.cwd())
Step-by-Step Solution
Solution:
  1. Step 1: Import pathlib with alias 'pl'

    Use 'import pathlib as pl' to alias the module.
  2. Step 2: Use pl.Path.cwd() and convert to string

    pl.Path.cwd() returns current path object; str() converts it to string.
  3. Final Answer:

    import pathlib as pl\nprint(str(pl.Path.cwd())) -> Option B
  4. Quick Check:

    Alias used correctly with proper function calls [OK]
Quick Trick: Use alias and call functions with alias name [OK]
Common Mistakes:
  • Calling functions on original module name
  • Using wrong function for cwd

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes