Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Convert string to int and float - Python Program

In Python, strings can be converted to integers using the int() function and to floating-point numbers using the float() function.

Converting a string to an integer:

The int() function is used to convert a string representing a whole number into an integer.

Converting a string to a float:

The float() function is used to convert a string representing a decimal number into a floating-point number.

str_val = "123" int_val = int(str_val) float_val = float(str_val) print(int_val) print(float_val)

Output

 
OUTPUT  :
123
123.0