【发布时间】:2016-02-16 08:43:49
【问题描述】:
我正在查看模拟考试的答案,这是其中一个问题的建议答案:
def multipal(word,n=None):
for i in range(len(word)):
if word[:i] == word[i-1::-1]:
repeat = word[:i]
if not n:
no_repeats = len(word)/i
else:
no_repeats = n
if word == repeat * no_repeats:
return True
return False
此函数的目的是确定输入单词是否是重复的“n”个回文(从前面读取的单词与从后面读取的单词相同,例如“aza”或“abba”)。例如,multipal('abaaba', 2) 将返回 True,但 multipal('abaaba', 3) 将返回 False。
我想知道的是为什么n在原始参数中被分配None,它真的会影响函数的其余部分吗?
【问题讨论】:
标签: python if-statement nonetype