Python. AttributeError: 'NoneType' object has no attribute 'startswith' Python. AttributeError: 'NoneType' object has no attribute 'startswith' powershell powershell

Python. AttributeError: 'NoneType' object has no attribute 'startswith'


In the first line of code, you are getting the attribute error because the code assumes that job contains a string, which has the method startswith(), but it doesn't contain a string, it contains None.

In the second line of code, you are not getting the attribute error because the code is testing to see if job contains None, before calling startswith() on it. Another (not quite equivalent but arguably better) way to express

lambda job: job and job.startswith('Internship')

is

lambda job: job.startswith('Internship') if job else False