Remove final character from string (Python)
This question already has an answer here:
Simple:
st = "abcdefghij"
st = st[:-1]
there is also another way that show how it is done with steps:
list1 = "abcdefghij"
list2 = list(list1)
print (list2)
list3 = list2[:-1]
print (list3)
This is also a way with the user inputting a word:
list1 = input ("Enter :")
list2 = list(list1)
print (list2)
list3 = list2[:-1]
print (list3)
To make it take away the last word in a list:
list1 = input ("Enter :")
list2 = list1.split()
print (list2)
list3 = list2[:-1]
print (list3)
链接地址: http://www.djcxy.com/p/26726.html
上一篇: 在Python列表索引中的冒号(:)