【问题标题】:Gets an extra “None” after “ word found” why? [duplicate]为什么在“找到单词”之后得到一个额外的“无”? [复制]
【发布时间】:2021-11-24 12:44:01
【问题描述】:
text = input()
word = input()

def search(tx, wd):
    if wd in tx:
        print("Word found")
    else:
        print("Word not found")   
    
print(search(text, word))

【问题讨论】:

标签: python


【解决方案1】:

search 不返回任何内容,因此当您尝试打印对search 的调用时,它会打印None。您可以删除最后一个打印功能并调用search

print(search(text,word)) # will print None

search(text,word) # will print "Word found" or "Word not found", no need to print again.

【讨论】:

  • 很好的答案,除了 search 返回对象 None。你不能什么都不返回,None 是你得到的最接近的。
猜你喜欢
  • 2023-01-25
  • 1970-01-01
  • 1970-01-01
  • 2019-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-27
  • 2015-06-20
相关资源
最近更新 更多