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 |
Does python have polymorphism?
What is deep copy in python?
Can we use else block with for loop? Answer with one example.
What objects are iterable in python?
How are data types defined in python?
What is a function for flatten an irregular list of lists?
How do you split a list into evenly sized chunks?
Is python the future of programming?
What statement is used in python if the statement is required syntactically but no action is required for the program?
Convert a string representation of list to list.
What is sphinx linux?
How can you randomize the items of a list in place in python?