Trick No. 1

Write a code in python which uses find() built-in function and string slicing to extract the number from the string at the end of the line below. Convert the extracted value to a floating point number and print it out.

text_string = “Manoj-Kumar-Tutoring-on-PYTHON:    0.1234”

Solution:

# First find the “:

t = text_string.find(“:”)

# Then, anything after : (including white spaces) be stored into another vector
num = float(text_string[t+1 : ])
# I converted string into float in the above operation

# Print variable

print num

That’s It.

 

 

 

Advertisements