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 the string does get converted to a number?



How the string does get converted to a number?..

Answer / chaitanya

• To convert the string into a number the built-in functions are used like int() constructor. It is a data type that is used like int (‘1’) ==1.

• float() is also used to show the number in the format as float(‘1’)=1.

• The number by default are interpreted as decimal and if it is represented by int(‘0x1’) then it gives an error as ValueError. In this the int(string,base) function takes the parameter to convert string to number in this the process will be like int(‘0x1’,16)==16. If the base parameter is defined as 0 then it is indicated by an octal and 0x indicates it as hexadecimal number.

• There is function eval() that can be used to convert string into number but it is a bit slower and present many security risks like __import__('os').system("rm -rf$HOME") - use of this will delete the home directory of the system.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

How to capitalize the first letter of each word in a string (python)?

0 Answers  


How will you distinguish between numpy and scipy?

0 Answers  


What advantages do numpy arrays offer over (nested) python lists?

0 Answers  


Does python supports interfaces like in java or c#?

0 Answers  


Are Tuples immutable?

0 Answers  


Why is button parameter “command” executed when declared?

0 Answers  


What is the use of pycharm?

0 Answers  


Is Python a good choice for web development

0 Answers  


What is the use of assertions in python?

0 Answers  


Explain about negative indexing?

0 Answers  


What are the various types of operators in Python?

2 Answers  


What are the optional statements that can be used inside a <try-except> block in python?

0 Answers  


Categories