How do I convert a string to a number?



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

Post New Answer

More Python Interview Questions

Which module is used to control the gpio in python?

0 Answers  


How can I wait until we receive data using python socket?

0 Answers  


How many hours should a person sleep?

0 Answers  


What are pandas in python?

0 Answers  


Does python have private?

0 Answers  


Can I learn python in a month?

0 Answers  


Explain deep copy in python?

0 Answers  


In pyton, what is a namespace?

0 Answers  


What is uuid format?

0 Answers  


What is set function in python?

0 Answers  


What are python’s dictionaries?

0 Answers  


What is a unit test in Python?

2 Answers  


Categories