判断一个字符串是否是对折的字符串,类似“peep”就为对折字符串。若“peap”虽然首位相同,但是str[1] =/= str[-2],所以它不是对折字符串
写一个函数,判断一个字符串是否是对折字符串,若是,返回True;若不是,则返回False
def peep_function(arg):str_len = len(arg)com_times = str_len/2start_point = 0end_point = str_len - 1while start_point <= com_times:if arg[start_point] == arg[end_point]:start_point += 1end_point -= 1if start_point == com_times:print "yes! peep function!"return Trueelse:print "no! not peep function!"return
arg = "peep"
print peep_function(arg)
本文发布于:2024-02-02 04:56:41,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170682101541497.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |