# converting a string to int, float by using int(), float()

# initializing string
s = "10110"

# convert string to int in base 2
c = int(s,2)
print ("The value of '10110' in base 2 is : ", c) # display 22

# convert string to int in base 10
c = int(s,10)
print ("The value of '10110' in base 10 is : ", c) # display 10110


# convert the string to float
f = float(s)
print ("After converting to float, f = : ", f) # display 10110.0

Younes Derfoufi
my-courses.net

Leave a Reply