我试图以各种可能的方式理解以下示例。
+---+---+---+---+---+---+---+---+---+
| C | O | M | P | U | T | E | R | S |
+---+---+---+---+---+---+---+---+---+
0 1 2 3 4 5 6 7 8 9
-9 -8 -7 -6 -5 -4 -3 -2 -1
COMPUTERS[ 4 : 7 ] = UTE
COMPUTERS[ 2 : 5 : 2 ] = MU
COMPUTERS[-5 : 1 :-1 ] = UPM
COMPUTERS[ 4 ] = U
COMPUTERS[-4 :-6 :-1 ] = TU
COMPUTERS[ 2 :-3 : 1 ] = MPUT
COMPUTERS[ 2 :-3 :-1 ] =
COMPUTERS[ : :-1 ] = SRETUPMOC
COMPUTERS[-5 : ] = UTERS
COMPUTERS[-5 : 0 :-1 ] = UPMO
COMPUTERS[-5 : :-1 ] = UPMOC
COMPUTERS[-1 : 1 :-2 ] = SEUM
但是除了中三,我没有其他方法
EXPECTED OUTPUT
Ex:
COMPUTERS = COMERS (only first three and last three not the middle three letters (PUT))
有人可以告诉我如何从开头到结尾(:3和6 :)
最佳答案
那不是一片,而是两片:
word[:3] + word[-3:]
关于python - 如何通过使用python中的slice运算符从中间部分提取字母?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30192776/