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 to give comments in python?
What is pytest in python?
Tell me how does the ternary operator work in python?
Can python be used for automation?
Is self a keyword in python?
How do you remove duplicates from a list in python whilst preserving order?
How do I run Apache in Python?
What is the most "pythonic" way to iterate over a list in chunks?
What does mean in python?
What does the __ init__ function do in python?
Is google made with python?
Does python have a-main() method?