Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAbhishek Kulkarni
4,405 PointsWhy isn't there simply an 'Hour' attribute?
Why did we have to calculate hours on our own? There are attributes for days, seconds and microseconds but why not hours which has a lot more use cases.
2 Answers
Steven Parker
231,275 PointsThe Python reference for timedelta says:
Only days, seconds and microseconds are stored internally. Arguments are converted to those units:
- A millisecond is converted to 1000 microseconds.
- A minute is converted to 60 seconds.
- An hour is converted to 3600 seconds.
- A week is converted to 7 days.
Only the language designers would know why they didn't break up the stored values further, but we might guess that it was for efficiency reasons, and because the other values can be easily calculated.
Idea: You could create your own sub-class that provides additional values as computed properties.
obhai maromujhe
Python Development Techdegree Student 1,723 PointsAfter watching this video I knew that this course was recorded in 2014. Does this still work? Or it is outdated??
Steven Parker
231,275 PointsWhy not try a little experiment and find out? Or just check the current official documentation.