How do I convert a string to a number?
Answer / chaitanya
Python contains several built-in functions to convert values from one data type to another data type.
The int function takes string and coverts it to an integer.
>>>s = "1234" # s is string
>>>i = int(s) # string converted to int
>>>print i+2
-------------------------
1236
The float function converts strings into float number.
>>>s = "1234.22" # s is string
>>>i = float(s) # string converted to float
>>>print i
-------------------------
1234.22
| Is This Answer Correct ? | 0 Yes | 0 No |
What is pack in python?
What is a static method in python?
Which is fastest implementation of python?
Why python is referred as glue code?
What is standard output in python?
What is python easy_install?
Explain how python does compile-time and run-time code checking?
What are Python's key features?
How do you dispose a variable in python?
Why are identifier names with a leading underscore disparaged?
Do you know what are the optional statements that can be used inside a <try-except> block in python?
What happens in the background when you run a python file?