remove first occurrence of string python code example
Example 1: how to remove first letter of a string python
s = "hello"
print s[1:]
Example 2: strip first occurence of substring python
>>>mystring = "Description: Mary had a little lamb Description: "
>>>print mystring.replace("Description: ","",1)
"Mary had a little lamb Description: "
Example 3: remove first character from string python
s = ":dfa:sif:e"
print(s[1:])
prints:
dfa:sif:e
Example 4: remove first occurrence of element from list python
Input :
list [10, 20, 30, 40, 30]
function call to remove 30 from the list:
list.remove(30)
Output:
List elements after removing 30
list [10, 20, 40, 30]