How do I convert a string to a number?

How do I convert a string to a number?

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
What is a negative index in python?
What is a negative index in python? - Python arrays & list items can be accessed with positive or negative numbers (also known as index)........
How do you make an array in Python?
How do you make an array in Python? - The array module contains methods for creating arrays of fixed types with homogeneous data types. Arrays are slower then list......
How to create a multidimensional list?
There are two ways in which Multidimensional list can be created: By direct initializing the list as shown below to create multidimlist below......
Post your comment