About 349,000 results
Open links in new tab
  1. python - How do I parse a string to a float or int? - Stack Overflow

    Dec 19, 2008 · In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 542.2222? Or parse the string "31" to an integer, 31? I just want to know how to …

  2. Convert integer to string in Python - Stack Overflow

    Jun 23, 2019 · There is no typecast and no type coercion in Python. You have to convert your variable in an explicit way. To convert an object into a string you use the str() function. It works …

  3. How can I convert a string to an int in Python? - Stack Overflow

    How to convert string to int in python? 7. Convert String to Int without int() 0.

  4. python - Best way to format integer as string with leading zeros ...

    The standard way is to use format string modifiers. These format string methods are available in most programming languages (via the sprintf function in c for example) and are a handy tool to …

  5. python - Convert all strings in a list to integers - Stack Overflow

    There are several methods to convert string numbers in a list to integers. In Python 2.x you can use the map function: >>> results = ['1', '2', '3'] >>> results = map(int, results) >>> results [1, 2, 3]

  6. python - How to change any data type into a string ... - Stack …

    Jul 8, 2010 · str is meant to produce a string representation of the object's data. If you're writing your own class and you want str to work for you, add:

  7. python - ValueError: invalid literal for int () with base 10 ...

    Jan 14, 2023 · Here you are trying to convert a string into int type which is not base-10. you can convert a string into int only if it is base-10 otherwise it will throw ValueError, stating invalid …

  8. python - How can I check if a string represents an int, without …

    Safely evaluate an expression node or a string containing a Python literal or container display. The string or node provided may only consist of the following Python literal structures: strings, …

  9. Converting String to Int using try/except in Python

    Nov 10, 2011 · print '"%s" cannot be converted to an int: %s' % (value, ex) ... 12345 as an int is 12345 67890 as an int is 67890 3.14 as an int is 3 42 as an int is 42 21 as an int is 21 254 as …

  10. Python: How do I convert an array of strings to an array of numbers?

    Mar 15, 2011 · Use int which converts a string to an int, inside a list ... Convert bytes to a string in Python 3.