Answer Posted / 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 View All Answers
What is the use of map in python?
Which module is used to control the gpio in python?
The following is displayed by a print function call?
What is the use of try, except, finally and raise in error handling?
Whenever you exit python, is all memory de-allocated?
What is filter python?
In python, are there any databases to DB packages?
How do you split a string in python?
What is the use of __ init __ py in python?
How can you share variables across modules?
Explain supported data types in python?
What is python? What do you understand of pep 8?
What is the shortest method to open a text file and display its content?
Explain python variable scope error?
Why are identifier names with a leading underscore disparaged?