question about output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Java and Swing

    #1

    question about output

    i have printed out some numbers and they look like

    10944800e
    10952560d

    ....if i want to later assign this type of number to variable how can i
    do it?

    for example i can't do...
    [color=blue][color=green]
    >> x = 10944800e[/color][/color]

    ...since it says "invalid token" on the "e".

    thanks.

  • Java and Swing

    #2
    Re: question about output

    doh! nevermind, my original output had e and d in it.

    Comment

    • Steven D'Aprano

      #3
      Re: question about output

      On Wed, 05 Oct 2005 07:24:31 -0700, Java and Swing wrote:
      [color=blue]
      > i have printed out some numbers and they look like
      >
      > 10944800e
      > 10952560d[/color]

      They don't look like numbers to me. They have letters at the end. What are
      they? What does the letter mean?

      [color=blue]
      > ...if i want to later assign this type of number to variable how can i
      > do it?
      >
      > for example i can't do...
      >[color=green][color=darkred]
      >>> x = 10944800e[/color][/color]
      >
      > ..since it says "invalid token" on the "e".[/color]

      How did you get the "numbers"? If you just typed them in by hand, then
      leave the "e" off and you have a number.

      If they are supposed to be hex numbers, then you can use:

      x = int("10944800e" , 16) # note the quote marks
      print x

      -> 4450451470

      If you don't care about the numeric value, then you just put quote marks
      around the number+letter:

      x = "10944800e"

      but then x will be a string, not a number.

      If none of these answers is what you need, you will need to explain your
      problem a little better.


      --
      Steven.

      Comment

      • utabintarbo@gmail.com

        #4
        Re: question about output

        Given that the format is consistent (and the last char is not part of
        the number you want), you can probably do something like this:

        x = int('10944800e'[:-1])

        Disclaimer: I am a n00b. YMMV ;-)

        Comment

        • Dennis Lee Bieber

          #5
          Re: question about output

          On 5 Oct 2005 07:24:31 -0700, "Java and Swing" <codecraig@gmai l.com>
          declaimed the following in comp.lang.pytho n:
          [color=blue]
          > i have printed out some numbers and they look like
          >
          > 10944800e
          > 10952560d
          >[/color]
          What did you use to print them out -- that will tell us how to read
          them...

          For example, if the above had a 0 behind the "e" or "d"...
          [color=blue][color=green][color=darkred]
          >>> a = "10944800e"
          >>> b = "10952560d"
          >>> print float(a)[/color][/color][/color]
          Traceback (most recent call last):
          File "<stdin>", line 1, in ?
          ValueError: invalid literal for float(): 10944800e[color=blue][color=green][color=darkred]
          >>> a = "10944800e0 "
          >>> print float(a)[/color][/color][/color]
          10944800.0[color=blue][color=green][color=darkred]
          >>> b = "10952560d0 "
          >>> print float(b)[/color][/color][/color]
          10952560.0[color=blue][color=green][color=darkred]
          >>>[/color][/color][/color]

          --[color=blue]
          > =============== =============== =============== =============== == <
          > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
          > wulfraed@dm.net | Bestiaria Support Staff <
          > =============== =============== =============== =============== == <
          > Home Page: <http://www.dm.net/~wulfraed/> <
          > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

          Comment

          Working...