Differences in Displaying the Output of a function x a method

Hi, everyone

I’m currently working on the “Building Fast Queries in a CSV in the Data Engineering Project”. In Step 3(“Finding a Laptop from the Id”) we’re asked to create a method that checks if a given Id is in the dataset or, if it’s not, returns None.

I my project, I wanted to change this a bit and output a message like “No Results found” instead of simply outputting None. However, my method does not seem to be able to output anything that isn’t None whenever there are no matches.

Here is the code I’m using:

class Inventory():

def __init__(self, csv_file):
    
    with open(csv_file) as data:
        data = list(csv.reader(data))
    
    self.header = data[0]
    self.rows = data[1:]
    
    def get_laptop_from_id(self, _id): 
        _id = str(_id)
        result = "No Matches Found"
        for r in self.rows:                  
            if row[0] == laptop_id:
                return row
        return result

inv.get_laptop_from_id(10000)

inv.get_laptop_from_id(any_value)

When I set “any_value” to a value that exists in the dataset, the output is the whole row, as it is meant to be. However, when I try with a value that is not in the dataset (5000), for example, the output is None.

The funny thing is, if I try to writea function that does something similar, I can control the output:

def get_laptop_from_id(_id):
    _id = str(_id)
    for r in inv.rows:
        if r[0] == _id:
            return r
    return "No Ids matched your search"

get_laptop_from_id(any_value)

With the function, if any value is in the dataset, I get the row back. If it’s not, I get the message “No ids matched your search”.

With that being said, is there anything I’m missing? Or is there any explanation for this behaviour?

Thanks in advance!