Extracting a piece of String in python

by anupmaurya
0 comment 548 views

We’re going to see strings of various kinds and various lengths and we’re going to want to extract pieces of them, okay? And so the idea is to somehow get this part out and then convert it to a floating point.

Suppose you have given a string

text=”python is my language version : 2.38″

and you have find the postion of the ” : ” in the string

ipos =text.find(‘:’)

As output you get the position of the “:” in the string.
that at 31 postion.

Now, if you have to print any piece of the code, Suppose you have to print “2.38” part of a text string, then


this will give you the part of the string .
now if you also want to convert it into floating point .
So,we here use type casting.

This is how you can extract a piece of string.

Happy Programming;)

You may also like