leetcode(1),reverse(python)

question:(将字符串逆向输出)

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

代码实现:

def reverse():
    string = raw_input('input a string:')
    words = []
    strCount = len(string)
    for i in range(strCount):
        words.append(string[strCount- i-1])
        i += 1
    rstr = ''.join(words)
    print rstr
刚入门,欢迎指正

----------------------------------------------2016.5.13-----------------------------------------------------

想到一个新方法:

def reverse(s):
    return ''.join(reversed(s))


你可能感兴趣的:(leetcode,python,leetcode)