Newbie question about lists

A

Austin Cox

Hello, I just started with python and have run into a problem using
lists.

If I enter:
li = [.25,.10,.05,.01]
and then enter:
print li
it'll output:
[0.25, 0.10000000000000001, 0.050000000000000003, 0.01]

Can anyone tell me why it does this, and how I can get just the value
..10, and .05 into a list? Thanks.
 
R

Robert Kern

Austin said:
Hello, I just started with python and have run into a problem using
lists.

If I enter:
li = [.25,.10,.05,.01]
and then enter:
print li
it'll output:
[0.25, 0.10000000000000001, 0.050000000000000003, 0.01]

Can anyone tell me why it does this, and how I can get just the value
.10, and .05 into a list? Thanks.

http://docs.python.org/tut/node16.html

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
P

Paul Rubin

Leo Jay said:
[Decimal("0.25"), Decimal("0.10"), Decimal("0.05"), Decimal("0.01")]

I wonder if we should have some special syntax for decimals: maybe

[$.25, $.10, $.05, $.01]

That would even fit in with decimals being used for financial quantities.
 
L

Leo Jay

IMO, python should use the decimal for default.
..25 is right for Decimal(".25").
isn't that better?
 
R

Robert Kern

Paul said:
Leo Jay said:
[Decimal("0.25"), Decimal("0.10"), Decimal("0.05"), Decimal("0.01")]

I wonder if we should have some special syntax for decimals: maybe

[$.25, $.10, $.05, $.01]

That would even fit in with decimals being used for financial quantities.

Various versions of the (several) Decimal PEPs had a decimal literal
syntax, usually along the lines of 0.25d. Google through the python-dev
archives.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top