0
0
Pythonprogramming~20 mins

Import aliasing in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Import Aliasing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of alias import usage
What is the output of this Python code using import aliasing?
Python
import math as m

result = m.sqrt(16)
print(result)
ANameError
B16
Csqrt(16)
D4.0
Attempts:
2 left
💡 Hint
Remember that aliasing lets you use a shorter name for a module.
Predict Output
intermediate
2:00remaining
Effect of aliasing on function call
What will be printed by this code snippet?
Python
from datetime import datetime as dt

now = dt.now()
print(type(now))
A<class 'datetime.datetime'>
B<class 'datetime.date'>
Cdatetime.now()
DAttributeError
Attempts:
2 left
💡 Hint
Check what dt.now() returns and its type.
🔧 Debug
advanced
2:00remaining
Identify the error caused by incorrect aliasing
What error does this code raise?
Python
import json as jsn

print(json.dumps({'a':1}))
AAttributeError
BNameError
CSyntaxError
DTypeError
Attempts:
2 left
💡 Hint
Look at the name used to call the function vs the alias.
🧠 Conceptual
advanced
2:00remaining
Understanding aliasing effect on namespace
After running this code, which names are defined in the current namespace?
Python
import os as operating_system
from math import sqrt as square_root

print(square_root(9))
Aoperating_system and square_root
Bos and square_root
Cos and sqrt
Doperating_system and sqrt
Attempts:
2 left
💡 Hint
Aliasing changes the names you use in your code.
📝 Syntax
expert
2:00remaining
Which import aliasing syntax is correct?
Which option correctly imports the module 'collections' with alias 'col'?
Afrom collections as col import *
Bfrom collections import * as col
Cimport collections as col
Dimport collections col
Attempts:
2 left
💡 Hint
The 'as' keyword is used after the module name in import statements.