
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to parse a string to float or int in python?
To parse a string to int, you can use the following:
try: print int('112') except ValueError: print 'Cannot parse'
This will give you the output:
112
To parse a string to float, you can use the following:
try: print float('112.15') except ValueError: print 'Cannot parse'
This will give you the output:
112.15
- Related Articles
- How to parse a string to an int in C++?
- How to parse a string into a nullable int in C#?
- How can I parse a numeric string to its corresponding float value?
- How to convert float to int in Swift?
- How to convert int to string in Python?
- How to convert Int data type to Float in Golang?
- How to parse float with two decimal places in JavaScript?
- How to convert hex string into int in Python?
- How to check if a string can be converted to float in Python?
- How to parse json string in android?
- How to parse a string from a JavaScript array?
- How to convert a String to an int in Java
- How to convert a string to int in Lua programming?
- How to convert int to String in java?
- How to convert a String into int in Java?

Advertisements