ÓãCÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
²é¿´: 2386|»Ø¸´: 2

[Òѽâ¾ö]Ϊʲôreturn»á±¨´í

[¸´ÖÆÁ´½Ó]
·¢±íÓÚ 2020-2-28 15:49:24 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ

ÂíÉÏ×¢²á£¬½á½»¸ü¶àºÃÓÑ£¬ÏíÓøü¶à¹¦ÄÜ^_^

ÄúÐèÒª µÇ¼ ²Å¿ÉÒÔÏÂÔØ»ò²é¿´£¬Ã»ÓÐÕ˺ţ¿Á¢¼´×¢²á

x
  1. def hwl(s):
  2.     if len(s) == 1:
  3.         return True
  4.     elif s[0] == s[len(s) - 1]:
  5.         if len(s) == 2:
  6.             return True
  7.         return hwl(s[1, len(s) - 2])
  8.     return False
¸´ÖÆ´úÂë

´úÂëÈçÉÏ¡£Ò»µ©Ö´ÐеÚÈý¸öreturn¾Í»á±¨´í¡£±¨´íÐÅÏ¢ÈçÏ£º
Traceback (most recent call last):
  File "D:\files\Python\my_funcs.py", line 18, in <module>
    hwl("abdsada")
  File "D:\files\Python\my_funcs.py", line 16, in hwl
    return hwl(s[1, len(s) - 2])
TypeError: string indices must be integers
×î¼Ñ´ð°¸
2020-2-28 15:52:13
return hwl(s[1: len(s) - 2])
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2020-2-28 15:52:13 | ÏÔʾȫ²¿Â¥²ã    ±¾Â¥Îª×î¼Ñ´ð°¸   
return hwl(s[1: len(s) - 2])
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
·¢±íÓÚ 2020-2-28 15:53:39 | ÏÔʾȫ²¿Â¥²ã
Â¥Ö÷µÄ·½·¨ÓÐÎÊÌ⣬°ïÄã¸ÄÁË£º

  1. def hwl(s):
  2.     print(s)
  3.     if len(s) == 1:
  4.         return True
  5.     elif s[0] == s[-1]:
  6.         if len(s) == 2:
  7.             return True
  8.         return hwl(s[1:-1])    # ÐÞ¸Ä
  9.     return False
¸´ÖÆ´úÂë
С¼×Óã×îÐÂ¿Î³Ì -> https://ilovefishc.com
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | Á¢¼´×¢²á

±¾°æ»ý·Ö¹æÔò

СºÚÎÝ|ÊÖ»ú°æ|Archiver|ÓãC¹¤×÷ÊÒ ( ÔÁICP±¸18085999ºÅ-1 | ÔÁ¹«Íø°²±¸ 44051102000585ºÅ)

GMT+8, 2026-3-1 21:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí