001、
>>> test1 = ["a", "b", "c", "d", "e", "f", "g"] ## 测试列表 >>> test1 ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> test1[2:-2] ## 同时删除首尾的两个字符 ['c', 'd', 'e'] >>> str1 = "abcdefg" ## 测试字符串 >>> str1 'abcdefg' >>> str1[2:-1] ## 删除字符串前两个字符、最后一个字符 'cdef' >>> tuple1 = (1, 2, 3, 4, 5, 6, 7) >>> tuple1[3:] (4, 5, 6, 7) >>> tuple1[2:-2] ## 应用于元组 (3, 4, 5)
标签:test1,tuple1,python,截取,元组,##,字符串,str1 From: https://www.cnblogs.com/liujiaxin2018/p/16588045.html