题解 | #数字颠倒#

数字颠倒

http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe

最简单的应该是倒序切片,但是方法不会了,所以用了字符串转列表然后又倒序拼接字符串 倒序切片

别人的一行代码

print(input()[::-1])

我的笨方法

n = input()
nlist = []
for i in n:
    nlist.append(i)
# print(nlist,type(nlist))
str1 = ''
index = -1
for j in range(len(nlist)):
    str1 = str1 + nlist[index]
    index = index - 1
print(str1)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务