Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Types and Branching If, Else and Elif

Edward Randall
Edward Randall
1,834 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 68,457 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!!