Skip to main content

Posts

Showing posts from February, 2018

Using find() and rfind() function in python 3

Suppose, we have a string "Bangladeshi people" and we need to search a character in this string. To  do this we can use find( ) built-in function in python 3. Let's see an example because an example help to remember a topics clearly and sharply. #The character is checked from left to right # it returns 12 which index number of  'p' character in that string string = "Bangladeshi people" check = string.find('p')  print(check) If we want to find a character from right to left ,we have to use rfind() function. Let's see, #The character is checked from right  to left # it returns 15 which index number of  'p' character in that string string = "Bangladeshi people" check = string.rfind('p')  print(check)

Using replace( ) function in python 3

replace( ) is used to replace or modify or reassign a new character in that string. Let's see a example because an example helps you to keep in mind that topics clearly. # Here is replace ' ' a space by a hyphen '-' # and after replacing all ' ' to '-' assign it to that string variable string = "Python Users Bangladesh" string =  string.replace(' ','-')    print (string) You can also replace characters from a string using a list. Comming Soon!