Python: String to Int conversion?

This is a discussion on Python: String to Int conversion? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I've got a string from which i'm extracting a number. I can get the number out of the string as ...

  1. #1
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301

    Python: String to Int conversion?

    I've got a string from which i'm extracting a number. I can get the number out of the string as a string itself, but ican't get it to be an integer.

    How do you do this in python? I don't see facilities for casting, nor do i see methods in the string class that would let me do this. There's no way that the language doesn't let you do this.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    num = int(str);
    This function can also take an optional radix. You can find the documentation at 2.1 Built-in Functions (scroll down).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 05:40 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21