+ 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

10th Sep 2017, 11:03 AM
LoneLySouL - avatar
5 Answers
+ 3
It think it is explained here: https://docs.python.org/3/library/datetime.html
10th Sep 2017, 11:51 AM
Paul - avatar
+ 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)
10th Sep 2017, 12:22 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
datetime itself is like a submodule within datetime (WTH Guido!) That internal datetime has functions
10th Sep 2017, 11:12 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
10th Sep 2017, 11:10 AM
Anton Gutman
Anton Gutman - avatar
+ 1
Thx guys
10th Sep 2017, 12:00 PM
LoneLySouL - avatar