You can choose to import only parts from a module, by using the from
keyword.
The module named mymodule
has one function and one dictionary:
def greeting(name):
print("Hello, " + name)
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
Import only the person1 dictionary from the module:
from mymodule import person1
print (person1["age"])
Note: When importing using the from
keyword, do not use the module name when referring to elements in the module. Example: person1["age"]
, not mymodule.person1["age"]
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4