+ 2
Python import datetime confusion
It there any difference between 'from datetime import datetime' and 'from datetime import date'? And what's the difference between from datetime import datetime n just import datetime? So confusing. Please help in detail Thanks
5 Answers
+ 3
It think it is explained here: https://docs.python.org/3/library/datetime.html
+ 8
Using a syntax: "from x import y" allows you to call y directly, instead of having to use the module prefix. You can use "from x import *" to import all methods of the module, but this is mostly unadvisable (as some imported methods may then overwrite the builtins).
Let's consider the following cases:
1. import math
2. from math import sqrt
3. from math import sqrt as s
Now, if you want to invoke a square root of 16, you type:
1. math.sqrt(16)
2. sqrt(16)
3. s(16)
+ 7
datetime itself is like a submodule within datetime (WTH Guido!)
That internal datetime has functions
+ 2
Okay
+ 1
Thx guys