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 can you convert a number to string?
List out standard datatypes in python
Why is this important?
What is a palindrome number?
Is python good for making apps?
What is metadata in python?
In which field python is used?
What do you think is the output of the following code fragment?
Explain the role of repr function.
How can I find the methods or attributes of an object in python?
What is the best front end for python?
What is the significance of ‘self' parameter in an object method? Should we always name this parameter as ‘self'?