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 pythonpath variable?
What is meant by mutex in python?
Why is numpy so fast?
How to print without newline or space?
What is class super?
What does != Mean in python 3?
How do you append to a list in python?
What is python's slice notation?
What is enumerate python?
Why are tuples immutable?
Explain the uses of the modules sqlite3, ctypes, pickle, traceback, and itertools.
What does do in python?