Noob questions about Python

Grant Edwards grante at visi.com
Wed Oct 17 15:47:14 EDT 2007


On 2007-10-17, Ixiaus <parnell.s at comcast.net> wrote:

> val = 'string'
> li = list(val)
> print li.reverse()
>
> returns nothing, but,
>
> val = 'string'
> li = list(val)
> li.reverse()
> print li
>
> returns what I want. Why does Python do that?

Because it does. :)

> Also I have been playing around with Binary math and noticed that
> Python treats:
>
> val = 00110
>
> as the integer 72 instead of returning 00110, why does Python do that?

In order to be "compatible" with the C language integer literal
convensions, integer litereals staring with a '0' are base-8,
so 00110 is

                  0 * 8^0         0
     +           1  * 8^1         8
     +          1   * 8^2        64
     +         0    * 8^3         0
     +        0     * 8^4         0
                               ----
                                 72                               

> (and how can I get around it?)

You can't.

-- 
Grant Edwards                   grante             Yow! Do you guys know we
                                  at               just passed thru a BLACK
                               visi.com            HOLE in space?



More information about the Python-list mailing list