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 are cookies python?
What are views in python?
Is python is easy?
What are “special” methods in python?
How do you add elements to a list in python?
How can we get home directory using '~' in python?
Which is better Python or ruby?
Is string immutable ?
How does mro work in python?
How does Python’s list.sort work at a high level? Is it stable? What’s the runtime?
Which the command you use to exit help window in python?
What does end do in python?