Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to find the last occurrence of a character in a string in python

original_string = "sentence one. sentence two. sentence three"

last_char_index = original_string.rfind(".")
new_string = original_string[:last_char_index] + "," + original_string
print(new_string)
"sentence one. sententce two, sentence three"
Comment

PREVIOUS NEXT
Code Example
Python :: python module with alphabet list 
Python :: django is null 
Python :: python datetime without seconds 
Python :: python print unicode character 
Python :: how to slice dataframe based on daterange in pandas 
Python :: pandas absolute value 
Python :: get last file in directory python 
Python :: python foresch 
Python :: python check if type 
Python :: python list remove spaces 
Python :: how to stop python prompt 
Python :: zlib decompress python 
Python :: identify the common columns between two dataframes pandas python 
Python :: train,test,dev python 
Python :: pandas transform date format? 
Python :: python get random character from string 
Python :: python get username windows 
Python :: python 1 to 01 
Python :: Python terminal colour 
Python :: python script to read all file names in a folder 
Python :: pandas convert date to quarter 
Python :: ffmpeg python cut video 
Python :: default ordering django 
Python :: python get computer name 
Python :: is vowel python 
Python :: FileExistsError: [Errno 17] File exists: 
Python :: dataframe, sort by columns 
Python :: printing python dictionary values 
Python :: tensorfow list devices 
Python :: star pattern in python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =