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 some good python projects?
Tell us what is module and package in python?
Do you need python to run a python program?
Can we change tuple values? If yes, give an example.
How do I start learning python?
What are some python projects for beginners?
What is the Java implementation of Python popularly known as?
What is python orm?
What is an elif in python?
How do you get the current working directory using python?
How to delete a file in python?
Is empty python dataframe?