整除和求模:定位个十百位
"""正整数的反转"""num = int(input('num = '))reversed_num = 0while num > 0:reversed_num = reversed_num * 10 + num % 10num //= 10print(reversed_num)
切片操作:复制列表or倒转列表
fruits = ['grape', 'apple', 'strawberry', 'waxberry']# 可以通过完整切片操作来复制列表fruits3 = fruits[:]print(fruits3) # ['grape', 'apple', 'strawberry', 'waxberry', 'pitaya', 'pear', 'mango']# 可以通过反向切片操作来获得倒转后的列表的拷贝fruits5 = fruits[::-1]print(fruits5) # ['mango', 'pear', 'pitaya', 'waxberry', 'strawberry', 'apple', 'grape']
