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 the difference between python and shell scripting?
What is set () in python?
How will you remove an object from a list?
What are the two main data types in python?
How do you protect python source code?
What is subclass in python?
Is javascript harder than python?
Explain me what is the purpose of doc strings in python?
Does python have a switch-case statement?
How do you use raw_input in python?
Can you run python programs without python installed?
What are key words in python?