python--切片[::1]的理解

n = 12345

str(n)[::-1]

#[::1]中省略起止位置,步进为-1

python中步进为正,从左往右取,步进为负,从右往左取

str(n)[::-1]实现字符串翻转

  1 2 3 4 5
index 0 1 2 3 4
index -5 -4 -3 -2 -1

你可能感兴趣的:(python)