剑指offer----翻转字符串

python实现:

def reverseString(aa):
    res=aa[::-1]
    return res

if __name__=="__main__":
    aa='ab.c.defg'
    print(reverseString(aa))
python列表基本操作
#更新列表
list=[]
list.append('Google')
print(list)
['Google']

#删除列表元素
list = ['physics', 'chemistry', 1997, 2000]
del list[1]
print(list)
['physics', 1997, 2000]

#python列表截取
list= ['Google', 'Runoob', 'Taobao']
print(list[-2])
'Runoob'
print(list[1:])
['Runoob', 'Taobao']

# max(list)
# 返回列表元素最大值
# min(list)
# 返回列表元素最小值

# list.count(obj)
# 统计某个元素在列表中出现的次数

# list.insert(index, obj)
# 将对象插入列表

# list.reverse()
# 反向列表中元素
# list.sort(cmp=None, key=None, reverse=False)
# 对原列表进行排序

python字符串操作----翻转字符串
使用字符串切片
result=s[::-1]

猜你喜欢

转载自blog.csdn.net/haoshan4783/article/details/88648069