{"id":14784,"date":"2021-09-30T12:00:14","date_gmt":"2021-09-30T06:30:14","guid":{"rendered":"https:\/\/python-programs.com\/?p=14784"},"modified":"2021-11-22T18:35:26","modified_gmt":"2021-11-22T13:05:26","slug":"python-program-to-remove-the-first-occurrence-of-character-in-a-string","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-remove-the-first-occurrence-of-character-in-a-string\/","title":{"rendered":"Python Program to Remove the First Occurrence of Character in a String"},"content":{"rendered":"

In this article, we’ll learn how to use Python to remove the first occurrence of a character in a string. The aim is to remove the first occurrence of a character in a string. To begin, locate the character in the string and confirm that it is the first occurrence. Finally, remove the character from the string and display the result.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String =goodmorningthisisbtechgeekspython\r\nGiven Character =s<\/pre>\n

Output:<\/strong><\/p>\n

The Given string after removing first occurence of the character [ s ] is goodmorningthisisbtechgeekspython\r\nThe Given string after removing first occurence of the character [ s ] is goodmorningthiisbtechgeekspython<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String =hellothisisbtechgeeks\r\nGiven Character =e<\/pre>\n

Output:<\/strong><\/p>\n

The Given string after removing first occurence of the character [ e ] is hellothisisbtechgeeks\r\nThe Given string after removing first occurence of the character [ e ] is hllothisisbtechgeeks<\/pre>\n

Program to Remove the First Occurrence of Character in a String in Python<\/h2>\n

Below are the ways to remove the first occurrence of the given character in a string in Python.<\/p>\n