Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a function return nothing?

Tags:

python

I have a function called crawl which will return a link to a website. Then I do something like:

found.append(crawl()) (found is a list)

This works fine as long as crawl returns a valid link, but sometimes it does not return anything. So a value of None gets added to the list.

So my question is that, is it possible to return something from crawl that will not not add anything to the list?

like image 937
xrisk Avatar asked Dec 01 '25 23:12

xrisk


1 Answers

In Python nothing is something: None. You have to use if-condition:

link = crawl()
if link is not None:
    found.append(link)

or let crawl return a list, which can contain one or zero elements:

found.extend(crawl())
like image 74
Daniel Avatar answered Dec 04 '25 11:12

Daniel