[Tutor] A couple newbie questions about Python
Lukáš Němec
lu.nemec at gmail.com
Thu Jun 12 07:49:52 CEST 2014
Hi, responses below...
Dne 11. 6. 2014 22:46, Deb Wyatt napsal(a):
> Hi. Everywhere I have read, the 'standard practice' for indentation is 4 spaces, but I am running into 2 space indentation in a lot of tutorials and such. Should I keep with the 4 spaces, or does it even matter, as long as it is consistent?
I recommend to use ammount of spaces that is consistent with already
existing project.
If it is a new project, use whatever you like - 4 spaces is recommended
(looks good :)
>
> I just recently became aware of the inaccuracy of calculations using floats and I am concerned about that.
If there are numerical operations where precision is necessary
(accounting or banking) use decimal type
from decimal import Decimal
a = Decimal('0.1')
b = Decimal('0.9')
print a + b
Note these numbers are passed to Decimal as a string, that is for a
reason - if you pass float to Decimal, it will already loose precision
and the whole thing doesn't make sense - and aslo will throw an exception.
>
> I am using Python 3, just fyi.
>
> Thanks for any enlightenment on these questions.
>
> Deb in WA, USA
>
> ____________________________________________________________
> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
> Check it out at http://www.inbox.com/marineaquarium
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
Lukas
More information about the Tutor
mailing list