# 切片语法:序列[起始索引:结束索引:步长],起始不写默认为0,结束不写默认取到结尾,步长不写默认为1(步长为-反向截取,最后一位起始序列为-1),左闭右开,切片后原序列不变
str = "lx,hahaha,呵呵"
str_slice1 = str[0:3:1]
print(f"str:{str}\nstr_slice1:{str_slice1}") # lx,
str_slice2 = str[-1:-4:-1] # 呵呵,
print(f"str_slice2:{str_slice2}")
list_num=[110,119,120,100,200,300] # 取出前三个数字 list_num1=list_num[0:3:1] print(f"list_num1: {list_num1}") #取出后三个数字,保持顺序不变 # 取出后三个数字 list_num2=list_num[-1:-4:-1] #反转数据 list_num2.reverse() print(f"list_num2: {list_num2}")