Discuss / Python / 交作业

交作业

Topic source

azshca_煜

#1 Created at ... [Delete] [Delete and Lock User]

刚开始想复杂了.....

m=str(n)
l=int(len(m)/2)
if l==0:
    return True
elif:

    return m[:l+len(m)%2]=m[:l-1:-1]

后来发现这样就行了......

 return str(n)==str(n)[::-1]

你好,请问一下str(n)[::-1]怎么理解?

azshca_煜

#3 Created at ... [Delete] [Delete and Lock User]

以-1为步数切分list,相当于从后往前切。

Garreteer

#4 Created at ... [Delete] [Delete and Lock User]

请教一下,当使用return str(n)==str(n)[::-1] 的时候,程序运行的时候,Python是检测到第一个False就结束这个比对过程,还是要把全部切片都比对完?


  • 1

Reply