您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何防止Python函数返回None

如何防止Python函数返回None

None如果在退出函数调用时未指定return ,Python将始终返回。您的选择是:

选项1(不满足条件时返回其他内容):

 def html_check(td, text):
     if td.text == text:
        value = td.find_next('td').text
        return value
     return "no value found"

选项2(如果None返回则忽略该函数):

if html_check(td, 'section'):
     # do things
python 2022/1/1 18:25:14 有173人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶