Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How do I convert a string to a number?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is input () in python?

885


List out loop breaking functions?

906


Is nan a float python?

896


How to append to a string in Python?

982


How to sort a dictionary by key in python?

882


What is pip and when it is used ?

941


How do you find missing values in python?

966


Are uuids sequential?

814


What is difference between sort and sorted in python?

997


What are the benefits of using python? What do you understand of pep 8?

965


Is python a keyword in python?

979


What if you want to toggle case for a python string?

944


What are python modules?

879


What is self and init in python?

1058


What are the tools that help to find bugs or perform analysis?

969