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 |
How long does it take to learn python?
How can you access the latest five entries of a DataFrame?
Explain how to copy an object in Python.
How does for loop and while loop differ in python and when do you choose to use them?
If while installing a package with pip, you get the error no matching installation found, what can you do?
What is the difference between ‘match’ and ‘search’ in python?
What are tuples used for?
Is python shell scripting?
What is the key difference between java and python?
What is tail recursion?
How do you write if else in python?
What is hashmap in python?