Python Python Basics Types and Branching If, Else and Elif

Edward Randall
Edward Randall
799 Points

AttributeError: 'NoneType'. What does this mean?

treehouse:~/workspace$ python hello.py
What is your first name? ebby
Hello, ebby
ebby is learning Python
Have a great day {}!
Traceback (most recent call last):
File "/home/treehouse/workspace/hello.py", line 6, in <module>
print("Have a great day {}!").format(first_name)
AttributeError: 'NoneType' object has no attribute 'format'

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 62,639 Points

The .format() is a string method and must be reference by attaching directly to a string with a period or "dot notation". By having the .format outside the print parens, it means running the .format method form the returned value of the print statements. The print command returns the None value. which does not have a .format method. Hence:

The NoneType object [returned from the print statement] has no attribute 'format'

Error messages in Python are surprisingly accurate. It's just that sometimes we don't always grasp their full meaning at first. How I figured it out was by asking myself is "What NoneType object is being referenced and where did it come from?"

Post back if you need more help. Good luck!!