Reverse a string in Python

前端 未结 28 2490
南旧
南旧 2020-11-21 04:41

There is no built in reverse function for Python\'s str object. What is the best way of implementing this method?

If supplying a very conci

28条回答
  •  梦毁少年i
    2020-11-21 04:46

    s = 'hello'
    ln = len(s)
    i = 1
    while True:
        rev = s[ln-i]
        print rev,
        i = i + 1
        if i == ln + 1 :
            break
    

    OUTPUT :

    o l l e h
    

提交回复
热议问题