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 type () in python?
Explain me what does the <self> keyword do?
In python, how do I read a file line-by-line into a list?
Is python zero indexed?
How type casting is done in python?
What is super () __ init__ in python?
Why python is better?
What is static in python?
What is __ name __ in python?
How to avoid having class data shared among instances in python?
How do you take input in python?
Is python fully object oriented?