pop a string in python code example
Example 1: python string pop
// no pop methode for strings (strings are immutable)
a = "abc"
last_letter = a[-1]
a = a[:-1]
Example 2: pop list python
#pop removes the last element
li=[1,2,3,4,5]
li.pop()
#>>>[1, 2, 3, 4]
Example 3: python list pop
# Python pop list
some_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # normal python list
print(some_list) # prints [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
some_list.pop() # pop() is used to pop out one index from a list (default index in pop is -1)
print(some_list) # prints [1, 2, 3, 4, 5, 6, 7, 8, 9]
=====================================================
# Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9]